36 lines
782 B
Python
36 lines
782 B
Python
from __future__ import unicode_literals
|
|
import yt_dlp
|
|
import sys
|
|
|
|
artist = ""
|
|
title = ""
|
|
print(sys.argv)
|
|
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': [{
|
|
'key': 'FFmpegExtractAudio',
|
|
'preferredcodec': 'mp3',
|
|
'preferredquality': '0', # 0 = best quality
|
|
}],
|
|
'outtmpl': template
|
|
}
|
|
|
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
ydl.download([url])
|