Skip to content

Commit

Permalink
feat: [dl-downer] add YouTube support
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianNoise committed May 3, 2024
1 parent 4b501ad commit cf5aea9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions dl-downer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pywidevine==1.8.0
playwright==1.42.0
python-dotenv
psycopg2-binary
yt-dlp
36 changes: 36 additions & 0 deletions dl-downer/src/downloaders/YOUTUBE.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions dl-downer/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf5aea9

Please sign in to comment.