diff --git a/config.toml b/config.toml index 1aa56c8..884a72d 100644 --- a/config.toml +++ b/config.toml @@ -9,6 +9,8 @@ agentPort = 10020 suMethod = "su -c" [download] +proxy = "" +parallelNum = 1 codecAlternative = true codecPriority = ["alac", "ec3", "ac3", "aac"] atmosConventToM4a = true diff --git a/src/api.py b/src/api.py index 52c45a8..fc09c6e 100644 --- a/src/api.py +++ b/src/api.py @@ -10,11 +10,19 @@ from tenacity import retry, retry_if_exception_type, stop_after_attempt, before_ from src.models import * -client = httpx.AsyncClient() -lock = asyncio.Semaphore(1) +client: httpx.AsyncClient +lock: asyncio.Semaphore user_agent_browser = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" user_agent_itunes = "iTunes/12.11.3 (Windows; Microsoft Windows 10 x64 Professional Edition (Build 19041); x64) AppleWebKit/7611.1022.4001.1 (dt:2)" -user_agent_app = "Music/5.7 Android/10 model/Pixel6GR1YH build/1234 (dt:66)" + + +def init_client_and_lock(proxy: str, parallel_num: int): + global client, lock + if proxy: + client = httpx.AsyncClient(proxy=proxy) + else: + client = httpx.AsyncClient() + lock = asyncio.Semaphore(parallel_num) @retry(retry=retry_if_exception_type((httpx.TimeoutException, httpcore.ConnectError, SSLError, FileNotFoundError)), diff --git a/src/cmd.py b/src/cmd.py index 1863201..87e123a 100644 --- a/src/cmd.py +++ b/src/cmd.py @@ -9,7 +9,7 @@ from prompt_toolkit import PromptSession, print_formatted_text, ANSI from prompt_toolkit.patch_stdout import patch_stdout from src.adb import Device -from src.api import get_token +from src.api import get_token, init_client_and_lock from src.config import Config from src.rip import rip_song, rip_album from src.types import GlobalAuthParams @@ -30,6 +30,7 @@ class NewInteractiveShell: def __init__(self, loop: asyncio.AbstractEventLoop): self.loop = loop self.config = Config.load_from_config() + init_client_and_lock(self.config.download.proxy, self.config.download.parallelNum) self.anonymous_access_token = loop.run_until_complete(get_token()) self.parser = argparse.ArgumentParser(exit_on_error=False) diff --git a/src/config.py b/src/config.py index ce4f7df..1ccaf35 100644 --- a/src/config.py +++ b/src/config.py @@ -16,6 +16,8 @@ class Device(BaseModel): class Download(BaseModel): + proxy: str + parallelNum: int codecAlternative: bool codecPriority: list[str] atmosConventToM4a: bool