mirror of
https://github.com/saveweb/biliarchiver.git
synced 2024-09-19 11:05:28 -07:00
feat(api): api
command
This commit is contained in:
parent
a123b5903c
commit
f05c9ae770
25
README.md
25
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
|
||||
|
@ -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__":
|
||||
|
@ -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()
|
Loading…
Reference in New Issue
Block a user