Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -26,7 +26,8 @@ class Download_Torrent(sh.Cmdlet):
|
||||
name="download-torrent",
|
||||
summary="Download torrent/magnet links via AllDebrid",
|
||||
usage="download-torrent <magnet|.torrent> [options]",
|
||||
alias=["torrent", "magnet"],
|
||||
alias=["torrent",
|
||||
"magnet"],
|
||||
arg=[
|
||||
sh.CmdletArg(
|
||||
name="magnet",
|
||||
@@ -78,7 +79,13 @@ class Download_Torrent(sh.Cmdlet):
|
||||
return 1
|
||||
for magnet_url in magnet_args:
|
||||
if background_mode:
|
||||
self._start_background_worker(magnet_url, output_dir, config, api_key, wait_timeout)
|
||||
self._start_background_worker(
|
||||
magnet_url,
|
||||
output_dir,
|
||||
config,
|
||||
api_key,
|
||||
wait_timeout
|
||||
)
|
||||
log(f"⧗ Torrent download queued in background: {magnet_url}")
|
||||
else:
|
||||
# Foreground mode: submit quickly, then continue processing in background
|
||||
@@ -88,7 +95,11 @@ class Download_Torrent(sh.Cmdlet):
|
||||
if magnet_id <= 0:
|
||||
continue
|
||||
self._start_background_magnet_worker(
|
||||
worker_id, magnet_id, output_dir, api_key, wait_timeout
|
||||
worker_id,
|
||||
magnet_id,
|
||||
output_dir,
|
||||
api_key,
|
||||
wait_timeout
|
||||
)
|
||||
log(f"⧗ Torrent processing started (ID: {magnet_id})")
|
||||
return 0
|
||||
@@ -116,11 +127,20 @@ class Download_Torrent(sh.Cmdlet):
|
||||
return 0
|
||||
|
||||
def _start_background_magnet_worker(
|
||||
self, worker_id: str, magnet_id: int, output_dir: Path, api_key: str, wait_timeout: int
|
||||
self,
|
||||
worker_id: str,
|
||||
magnet_id: int,
|
||||
output_dir: Path,
|
||||
api_key: str,
|
||||
wait_timeout: int
|
||||
) -> None:
|
||||
thread = threading.Thread(
|
||||
target=self._download_magnet_worker,
|
||||
args=(worker_id, magnet_id, output_dir, api_key, wait_timeout),
|
||||
args=(worker_id,
|
||||
magnet_id,
|
||||
output_dir,
|
||||
api_key,
|
||||
wait_timeout),
|
||||
daemon=True,
|
||||
name=f"TorrentWorker_{worker_id}",
|
||||
)
|
||||
@@ -155,7 +175,8 @@ class Download_Torrent(sh.Cmdlet):
|
||||
return
|
||||
|
||||
files_result = client.magnet_links([magnet_id])
|
||||
magnet_files = files_result.get(str(magnet_id), {})
|
||||
magnet_files = files_result.get(str(magnet_id),
|
||||
{})
|
||||
files_array = magnet_files.get("files", [])
|
||||
if not files_array:
|
||||
log(f"[Worker {worker_id}] No files found", file=sys.stderr)
|
||||
@@ -174,7 +195,8 @@ class Download_Torrent(sh.Cmdlet):
|
||||
worker_id: str,
|
||||
magnet_url: str,
|
||||
output_dir: Path,
|
||||
config: Dict[str, Any],
|
||||
config: Dict[str,
|
||||
Any],
|
||||
api_key: str,
|
||||
wait_timeout: int = 600,
|
||||
worker_manager: Optional[Any] = None,
|
||||
@@ -204,7 +226,8 @@ class Download_Torrent(sh.Cmdlet):
|
||||
log(f"[Worker {worker_id}] Timeout waiting for magnet", file=sys.stderr)
|
||||
return
|
||||
files_result = client.magnet_links([magnet_id])
|
||||
magnet_files = files_result.get(str(magnet_id), {})
|
||||
magnet_files = files_result.get(str(magnet_id),
|
||||
{})
|
||||
files_array = magnet_files.get("files", [])
|
||||
if not files_array:
|
||||
log(f"[Worker {worker_id}] No files found", file=sys.stderr)
|
||||
@@ -231,11 +254,23 @@ class Download_Torrent(sh.Cmdlet):
|
||||
except Exception as e:
|
||||
log(f"File download failed: {e}", file=sys.stderr)
|
||||
|
||||
def _start_background_worker(self, magnet_url, output_dir, config, api_key, wait_timeout):
|
||||
def _start_background_worker(
|
||||
self,
|
||||
magnet_url,
|
||||
output_dir,
|
||||
config,
|
||||
api_key,
|
||||
wait_timeout
|
||||
):
|
||||
worker_id = f"torrent_{uuid.uuid4().hex[:6]}"
|
||||
thread = threading.Thread(
|
||||
target=self._download_torrent_worker,
|
||||
args=(worker_id, magnet_url, output_dir, config, api_key, wait_timeout),
|
||||
args=(worker_id,
|
||||
magnet_url,
|
||||
output_dir,
|
||||
config,
|
||||
api_key,
|
||||
wait_timeout),
|
||||
daemon=True,
|
||||
name=f"TorrentWorker_{worker_id}",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user