yt2mp3/download.py
20xd6 d6a7b56bcf Catch for notification
plyer fails on Ubuntu with XFCE
2023-09-15 09:52:20 -04:00

45 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.")