45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
try:
|
||
import yt_dlp as yt
|
||
from plyer import notification
|
||
except:
|
||
import os
|
||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||
print("Please install dependances.\n" +
|
||
"This can be done with the command 'pip3 install -r " + script_dir + "/requierments.txt'")
|
||
|
||
def get(yt_url):
|
||
ytdl_options = {
|
||
'continuedl': True,
|
||
'ignoreerrors': True,
|
||
'outtmpl': '%(title)s.%(ext)s',
|
||
'no_warning': True,
|
||
'progress_hooks': [dl_progress],
|
||
#'quiet': True,
|
||
'writethumbnail': True,
|
||
'embed_metadata': True,
|
||
'format': 'any/bestaudio/best',
|
||
# ℹ️ See help(yt_dlp.postprocessor) for a list of available Postprocessors and their arguments
|
||
'postprocessors': [{ # Extract audio using ffmpeg,
|
||
'key': 'FFmpegExtractAudio',
|
||
'preferredcodec': 'mp3',
|
||
},{'key': 'FFmpegMetadata'},
|
||
{'key': 'EmbedThumbnail'},]
|
||
}
|
||
|
||
with yt.YoutubeDL(ytdl_options) as ytdl:
|
||
ytdl.download(yt_url)
|
||
try:
|
||
notification.notify(
|
||
title = "yt2mp3",
|
||
message = "Download and conversion complete.",
|
||
app_icon = None,
|
||
timeout = 3,
|
||
)
|
||
except:
|
||
print("Notification failed.")
|
||
|
||
|
||
|
||
def dl_progress(d):
|
||
if (d['status'] == 'finished'):
|
||
print("\nDownload completed.") |