yt2mp3/download.py
20xd6 dc8c561576 Update the notification system
This is to resolve issue #8.
2023-09-20 18:48:43 -04:00

43 lines
1.3 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 notifypy import Notify
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()
notification.title = "yt2mp3"
notification.message = "Download and conversion complete."
notification.send()
except:
print("Notification failed.")
def dl_progress(d):
if (d['status'] == 'finished'):
print("\nDownload completed.")