fix: Remote typer dependency
This commit is contained in:
+22
-24
@@ -1,10 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import httpx
|
import argparse
|
||||||
import subprocess
|
|
||||||
import logging
|
import logging
|
||||||
import typer
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
format="%(levelname)s %(asctime)s: %(message)s",
|
format="%(levelname)s %(asctime)s: %(message)s",
|
||||||
@@ -15,8 +16,6 @@ logging.getLogger("httpx").setLevel(logging.WARNING)
|
|||||||
# get api token from https://real-debrid.com/apitoken
|
# get api token from https://real-debrid.com/apitoken
|
||||||
key = "P4SUGS4VSXLDIRXSOAB46DXMU2HVFJTOWYCACNULX4V7TOZRW2BA"
|
key = "P4SUGS4VSXLDIRXSOAB46DXMU2HVFJTOWYCACNULX4V7TOZRW2BA"
|
||||||
|
|
||||||
cli = typer.Typer()
|
|
||||||
|
|
||||||
http = httpx.Client(
|
http = httpx.Client(
|
||||||
base_url="https://api.real-debrid.com/rest/1.0/",
|
base_url="https://api.real-debrid.com/rest/1.0/",
|
||||||
headers={"Authorization": f"Bearer {key}"},
|
headers={"Authorization": f"Bearer {key}"},
|
||||||
@@ -29,9 +28,7 @@ def get_download_url(url: str) -> str:
|
|||||||
return res.json()["download"]
|
return res.json()["download"]
|
||||||
|
|
||||||
|
|
||||||
def download_with_aria2(
|
def download_with_aria2(url: str, cwd: Path = Path.cwd(), extra_args: list[str] = None) -> None:
|
||||||
url: str, cwd: Path = Path.cwd(), extra_args: list[str] = None
|
|
||||||
) -> None:
|
|
||||||
if not extra_args:
|
if not extra_args:
|
||||||
extra_args = []
|
extra_args = []
|
||||||
args = ["aria2c", "-x", "5", url, *extra_args]
|
args = ["aria2c", "-x", "5", url, *extra_args]
|
||||||
@@ -39,33 +36,34 @@ def download_with_aria2(
|
|||||||
subprocess.run(args, text=True, cwd=str(cwd.resolve()))
|
subprocess.run(args, text=True, cwd=str(cwd.resolve()))
|
||||||
|
|
||||||
|
|
||||||
@cli.command(
|
def parse_args():
|
||||||
context_settings={
|
arger = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
"ignore_unknown_options": True,
|
arger.add_argument('url', help='URL to unrestrict & download')
|
||||||
"allow_extra_args": True,
|
arger.add_argument(
|
||||||
}
|
'--output-dir', '-o', '--out', dest='cwd', help='Output directory', type=Path, default=Path.cwd()
|
||||||
)
|
)
|
||||||
def main(
|
args, extra = arger.parse_known_args()
|
||||||
ctx: typer.Context,
|
return args, extra
|
||||||
url: str,
|
|
||||||
cwd: Path = typer.Option(Path("."), "-o", "--out", "--cwd", writable=True),
|
|
||||||
):
|
def main():
|
||||||
|
args, aria2c_args = parse_args()
|
||||||
try:
|
try:
|
||||||
logging.debug("generating premium link")
|
logging.debug("generating premium link")
|
||||||
download_url = get_download_url(url)
|
download_url = get_download_url(args.url)
|
||||||
except (httpx.HTTPStatusError, KeyError):
|
except (httpx.HTTPStatusError, KeyError):
|
||||||
logging.error("cannot generate premium link")
|
logging.error("cannot generate premium link")
|
||||||
raise typer.Exit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
logging.info("got url=%s", download_url)
|
logging.info("got url=%s", download_url)
|
||||||
|
|
||||||
logging.debug("passing url to aria2")
|
logging.debug("passing url to aria2")
|
||||||
try:
|
try:
|
||||||
download_with_aria2(download_url, cwd=cwd, extra_args=ctx.args)
|
download_with_aria2(download_url, cwd=args.cwd, extra_args=aria2c_args)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logging.error("download interrupted. exiting")
|
logging.error("download interrupted. exiting")
|
||||||
raise typer.Exit(2)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user