Allow setting artist and title for youtube download

This commit is contained in:
SemvdHoeven
2026-05-08 15:35:04 +02:00
parent 2c35d5fed0
commit da1e51db21

View File

@@ -2,6 +2,24 @@ from __future__ import unicode_literals
import yt_dlp
import sys
artist = ""
title = ""
if len(sys.argv) == 4:
artist = sys.argv[2]
title = sys.argv[3]
elif len(sys.argv) != 2:
print("Usage: python download_youtube.py <url> [<artist> <title>]")
sys.exit(1)
url = sys.argv[1]
template = ""
if (artist and title):
template = f"{artist} - {title}.%(ext)s"
else:
template = '%(uploader)s - %(title)s.%(ext)s'
print("Downloading youtube song " + url)
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
@@ -9,11 +27,8 @@ ydl_opts = {
'preferredcodec': 'mp3',
'preferredquality': '0', # 0 = best quality
}],
'outtmpl': '%(uploader)s - %(title)s.%(ext)s'
'outtmpl': template
}
url = sys.argv[1]
print("Downloading youtube song " + url)
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])