diff --git a/CONFIG.md b/CONFIG.md index 89cc4dc..f97b9cc 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -128,6 +128,15 @@ AMZN: bitrate: CVBR ``` +## downloader (str) + +Choose what software to use to download data throughout Devine where needed. + +Options: + +- `aria2c` (default) - https://github.com/aria2/aria2 +- `saldl` - https://github.com/saldl/saldl + ## headers (dict) Case-Insensitive dictionary of headers that all Services begin their Request Session state with. diff --git a/devine/commands/dl.py b/devine/commands/dl.py index 26be204..b1d515a 100644 --- a/devine/commands/dl.py +++ b/devine/commands/dl.py @@ -1,6 +1,5 @@ from __future__ import annotations -import asyncio import html import logging import math @@ -43,7 +42,7 @@ from devine.core.config import config from devine.core.console import console from devine.core.constants import AnyTrack, context_settings from devine.core.credential import Credential -from devine.core.downloaders import aria2c +from devine.core.downloaders import downloader from devine.core.drm import DRM_T, Widevine from devine.core.manifests import DASH, HLS from devine.core.proxies import Basic, Hola, NordVPN @@ -906,13 +905,13 @@ class dl: if self.DL_POOL_SKIP.is_set(): progress(downloaded="[yellow]SKIPPED") else: - asyncio.run(aria2c( + downloader( uri=track.url, out=save_path, headers=service.session.headers, proxy=proxy if track.needs_proxy else None, progress=progress - )) + ) track.path = save_path diff --git a/devine/core/config.py b/devine/core/config.py index 56eb459..bec0a8d 100644 --- a/devine/core/config.py +++ b/devine/core/config.py @@ -49,6 +49,8 @@ class Config: continue setattr(self.directories, name, Path(path).expanduser()) + self.downloader = kwargs.get("downloader") or "aria2c" + self.filenames = self._Filenames() for name, filename in (kwargs.get("filenames") or {}).items(): setattr(self.filenames, name, filename) diff --git a/devine/core/downloaders/__init__.py b/devine/core/downloaders/__init__.py index 4ce3274..a39bb73 100644 --- a/devine/core/downloaders/__init__.py +++ b/devine/core/downloaders/__init__.py @@ -1,4 +1,5 @@ from .aria2c import aria2c from .saldl import saldl +from .downloader import downloader -__ALL__ = (aria2c, saldl) +__ALL__ = (downloader, aria2c, saldl) diff --git a/devine/core/downloaders/downloader.py b/devine/core/downloaders/downloader.py new file mode 100644 index 0000000..64b8174 --- /dev/null +++ b/devine/core/downloaders/downloader.py @@ -0,0 +1,11 @@ +import asyncio +from functools import partial + +from devine.core.config import config +from devine.core.downloaders import aria2c, saldl + + +downloader = { + "aria2c": partial(asyncio.run, aria2c), + "saldl": partial(asyncio.run, saldl) +}[config.downloader] diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index 2ced4c0..09cd7ad 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -1,6 +1,5 @@ from __future__ import annotations -import asyncio import base64 import logging import math @@ -26,7 +25,7 @@ from requests import Session from rich import filesize from devine.core.constants import AnyTrack -from devine.core.downloaders import aria2c +from devine.core.downloaders import downloader from devine.core.drm import Widevine from devine.core.tracks import Audio, Subtitle, Tracks, Video from devine.core.utilities import is_close_match @@ -487,14 +486,14 @@ class DASH: segment_save_path.parent.mkdir(parents=True, exist_ok=True) segment_save_path.write_bytes(res.content) else: - asyncio.run(aria2c( + downloader( uri=segment_uri, out=segment_save_path, headers=session.headers, proxy=proxy, silent=attempts != 5, segmented=True - )) + ) break except Exception as ee: if stop_event.is_set() or attempts == 5: diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index e9d7ad3..ceb8f1a 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -1,6 +1,5 @@ from __future__ import annotations -import asyncio import logging import re import sys @@ -24,7 +23,7 @@ from requests import Session from rich import filesize from devine.core.constants import AnyTrack -from devine.core.downloaders import aria2c +from devine.core.downloaders import downloader from devine.core.drm import DRM_T, ClearKey, Widevine from devine.core.tracks import Audio, Subtitle, Tracks, Video from devine.core.utilities import is_close_match @@ -308,14 +307,14 @@ class HLS: segment_save_path.parent.mkdir(parents=True, exist_ok=True) segment_save_path.write_bytes(res.content) else: - asyncio.run(aria2c( + downloader( uri=segment.uri, out=segment_save_path, headers=session.headers, proxy=proxy, silent=attempts != 5, segmented=True - )) + ) break except Exception as ee: if stop_event.is_set() or attempts == 5: