diff --git a/README.md b/README.md index 4b7648c..a94ae6e 100644 --- a/README.md +++ b/README.md @@ -16,27 +16,52 @@ pip install biliarchiver biliarchiver --help ``` +### Basic usage + Follow these steps to start archiving: 1. Initialize a new workspace in current working directory: + ```bash biliarchiver init ``` + 2. Provide cookies and tokens following instructions: + ```bash biliarchiver auth ``` + 3. Download videos from BiliBili: + ```bash biliarchiver down --bvids BVXXXXXXXXX ``` + - This command also accepts a list of BVIDs or path to a file. Details can be found in `biliarchiver down --help`. + 4. Upload videos to Internet Archive: + ```bash biliarchiver up --bvids BVXXXXXXXXX ``` + - This command also accepts a list of BVIDs or path to a file. Details can be found in `biliarchiver up --help`. +### Rest API + +1. Start server + +```bash +biliarchiver api +``` + +2. Add videos + +```bash +curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:8000/archive/BVXXXXXX +``` + ## Develop ### Install diff --git a/biliarchiver/cli_tools/biliarchiver.py b/biliarchiver/cli_tools/biliarchiver.py index 0d957b7..77188db 100644 --- a/biliarchiver/cli_tools/biliarchiver.py +++ b/biliarchiver/cli_tools/biliarchiver.py @@ -79,7 +79,14 @@ def auth(): click.echo(click.style("Internet archive", bg="yellow")) click.echo(_("前往 https://archive.org/account/s3.php 获取 Access Key 和 Secret Key。")) click.echo(_("""将它们放在 `config.json` 指定的文件(默认为 `~/.bili_ia_keys.txt`)中,两者由换行符分隔。""")) - + + +@biliarchiver.command(help=click.style(_("运行 API"), fg="cyan")) +def api(): + from biliarchiver.rest_api.main import app + import uvicorn + + uvicorn.run(app) if __name__ == "__main__": diff --git a/biliarchiver/rest_api/scheduler.py b/biliarchiver/rest_api/scheduler.py deleted file mode 100644 index 56b7dcf..0000000 --- a/biliarchiver/rest_api/scheduler.py +++ /dev/null @@ -1,28 +0,0 @@ -import asyncio -from biliarchiver.rest_api.bilivid import BiliVideo - - -class ArchiveScheduler: - def __init__(self) -> None: - self.queue = [] - self.loop = asyncio.get_event_loop() - self.loop.run_until_complete(self.main()) - self.should_stop = False - - async def main(self): - while True: - if self.should_stop: - break - if len(self.queue) > 0: - vid = self.queue.pop(0) - await vid.down() - await vid.up() - else: - await asyncio.sleep(5) - - def add(self, vid: BiliVideo): - self.queue.append(vid) - - def stop(self): - self.should_stop = True - self.loop.close()