mirror of
https://github.com/saveweb/biliarchiver.git
synced 2024-09-19 11:05:28 -07:00
feat(api): ready to use
This commit is contained in:
parent
7e800ac09a
commit
955c3c0b3d
@ -82,30 +82,15 @@ def auth():
|
||||
|
||||
|
||||
@biliarchiver.command(help=click.style(_("运行 API"), fg="cyan"))
|
||||
@click.option(
|
||||
"--host",
|
||||
type=str,
|
||||
default="127.0.0.1",
|
||||
show_default=True,
|
||||
)
|
||||
@click.option(
|
||||
"--port",
|
||||
type=int,
|
||||
default=8000,
|
||||
show_default=True,
|
||||
)
|
||||
def api(**kwargs):
|
||||
def api():
|
||||
try:
|
||||
import fastapi
|
||||
import uvicorn
|
||||
except ImportError:
|
||||
print("Please install fastapi and uvicorn first.")
|
||||
print('pip install "uvicorn[standard]" fastapi')
|
||||
return
|
||||
|
||||
from biliarchiver.rest_api.main import app
|
||||
|
||||
uvicorn.run(app, **kwargs)
|
||||
print("Please fastapi first")
|
||||
print('pip install fastapi')
|
||||
print("------------------------")
|
||||
print("Then, install any ASGI server you like and to run the app manually: (<https://fastapi.tiangolo.com/deployment/manually/>)")
|
||||
print('biliarchiver.rest_api.main:app')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -3,10 +3,6 @@ from enum import Enum
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from biliarchiver.cli_tools.bili_archive_bvids import _down
|
||||
from biliarchiver.cli_tools.up_command import DEFAULT_COLLECTION
|
||||
|
||||
|
||||
class VideoStatus(str, Enum):
|
||||
pending = "pending"
|
||||
downloading = "downloading"
|
||||
@ -37,14 +33,20 @@ class BiliVideo:
|
||||
try:
|
||||
process = await asyncio.create_subprocess_exec(*cmd)
|
||||
retcode = await process.wait()
|
||||
except (KeyboardInterrupt, SystemExit, Exception):
|
||||
process = None
|
||||
except (KeyboardInterrupt, SystemExit, Exception) as e:
|
||||
if process:
|
||||
process.terminate()
|
||||
await process.wait()
|
||||
print("download terminated")
|
||||
print("download terminated:", e)
|
||||
return -1
|
||||
else:
|
||||
return retcode
|
||||
finally:
|
||||
if process:
|
||||
process.terminate()
|
||||
await process.wait()
|
||||
print("download terminated: (finally)")
|
||||
|
||||
async def up(self) -> int:
|
||||
from asyncio import subprocess
|
||||
@ -56,11 +58,17 @@ class BiliVideo:
|
||||
try:
|
||||
process = await subprocess.create_subprocess_exec(*cmd)
|
||||
retcode = await process.wait()
|
||||
except (KeyboardInterrupt, SystemExit, Exception):
|
||||
process = None
|
||||
except (KeyboardInterrupt, SystemExit, Exception) as e:
|
||||
if process:
|
||||
process.terminate()
|
||||
await process.wait()
|
||||
print("upload terminated")
|
||||
print("upload terminated", e)
|
||||
return -1
|
||||
else:
|
||||
return retcode
|
||||
finally:
|
||||
if process:
|
||||
process.terminate()
|
||||
await process.wait()
|
||||
print("upload terminated: (finally)")
|
||||
|
Loading…
Reference in New Issue
Block a user