diff --git a/dl-downer/requirements.txt b/dl-downer/requirements.txt index f82acc4..98ea713 100644 --- a/dl-downer/requirements.txt +++ b/dl-downer/requirements.txt @@ -5,3 +5,4 @@ pywidevine==1.8.0 playwright==1.42.0 python-dotenv psycopg2-binary +yt-dlp diff --git a/dl-downer/src/downloaders/YOUTUBE.py b/dl-downer/src/downloaders/YOUTUBE.py new file mode 100644 index 0000000..d90a8e2 --- /dev/null +++ b/dl-downer/src/downloaders/YOUTUBE.py @@ -0,0 +1,36 @@ +import os +import subprocess + +from loguru import logger + +from ..models.dl_request import DLRequest + +def YOUTUBE_DL(dl_request: DLRequest): + + command = [ 'yt-dlp', + '--yes-playlist', + '-N', '4', + '--restrict-filenames', + '--write-subs', + '--sub-langs', 'all', + '--merge-output-format', 'mkv', + ] + + if dl_request.preferred_quality_matcher: + p = dl_request.preferred_quality_matcher + command.extend([ '-f', f'bv[height<={p}]+ba/b[height<={p}]' ]) + + filename = '%(title)s.%(ext)s' + if dl_request.output_filename: + filename = f'{dl_request.output_filename}.%(ext)s' + file_path = os.path.join( + os.getenv('DOWNLOADS_FOLDER', './downloads'), + dl_request.platform, + filename, + ) + + command.extend([ '-o', file_path ]) + command.extend([ dl_request.video_page_or_manifest_url ]) + + logger.debug(f'Running command: {command}') + subprocess.run(command) diff --git a/dl-downer/src/server.py b/dl-downer/src/server.py index 07b166c..7b9c3fa 100644 --- a/dl-downer/src/server.py +++ b/dl-downer/src/server.py @@ -57,6 +57,9 @@ def start_server(): elif dl_request.platform == DLRequestPlatform.GENERIC_MANIFEST.value: from .downloaders.GENERIC_MANIFEST import GENERIC_MANIFEST_DL GENERIC_MANIFEST_DL(dl_request) + elif dl_request.platform == DLRequestPlatform.YOUTUBE.value: + from .downloaders.YOUTUBE import YOUTUBE_DL + YOUTUBE_DL(dl_request) else: logger.error(f'Unsupported platform: {dl_request.platform}') # throw error for now