feat(api): api command

This commit is contained in:
OverflowCat 2023-10-16 16:58:53 +08:00 committed by yzqzss
parent a123b5903c
commit f05c9ae770
3 changed files with 33 additions and 29 deletions

View File

@ -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

View File

@ -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__":

View File

@ -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()