11 Commits

Author SHA1 Message Date
d6a7b56bcf Catch for notification
plyer fails on Ubuntu with XFCE
2023-09-15 09:52:20 -04:00
bafe53e3a5 Cleanup cmd options 2023-09-14 10:28:14 -04:00
5aa80c6fc9 Catch missing imports 2023-09-14 10:28:00 -04:00
35223a70b0 Shorten the notification timeout 2023-09-14 10:01:56 -04:00
3deefbadd8 Merge pull request 'Adds a basic notification on completion' (#7) from issue#3 into master
Reviewed-on: #7
2023-09-13 22:40:19 -04:00
5ff3842e2c Adds a basic notification on completion
This is for issue #6.
2023-09-13 22:28:47 -04:00
ec7e2036fb Merge pull request 'Python conversion' (#2) from issue#1 into master
Reviewed-on: #2
2023-09-13 18:58:01 -04:00
b6518fba3c Remove the shell script 2023-09-13 18:55:28 -04:00
5ce6f618ac Basic working script
Updated the gitnore for media files.
2023-09-13 18:36:48 -04:00
5b279bc957 Add requierments.txt for pythong package control 2023-09-13 14:48:31 -04:00
b5480c63e6 Update .gitignore for venv 2023-09-13 14:48:07 -04:00
6 changed files with 75 additions and 2 deletions

9
.gitignore vendored
View File

@@ -1,3 +1,5 @@
*.mp3
*.webp
# ---> Linux
*~
@@ -143,6 +145,13 @@ venv/
ENV/
env.bak/
venv.bak/
bin/
include/
lib/
lib64/
share/
pyvenv.*
lib64
# Spyder project settings
.spyderproject

45
download.py Normal file
View File

@@ -0,0 +1,45 @@
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.")

2
requierments.txt Normal file
View File

@@ -0,0 +1,2 @@
yt-dlp
plyer

1
yt2mp3 Symbolic link
View File

@@ -0,0 +1 @@
yt2mp3.py

18
yt2mp3.py Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env python3
import argparse
import download
script_version = "0.2"
help_epilog = ("This script is very dependent on yt-dlp.\n"+
"If it's not working properly try updating yt-dlp.")
cmd_option_set = argparse.ArgumentParser(description='Backup YouTube channels.', epilog=help_epilog)
cmd_option_set.add_argument('--version', '-v', dest='print_version', action='store_true', help='Print the current version number.')
cmd_option_set.add_argument(dest='url_to_convert', default='', metavar="YT URL", nargs=argparse.REMAINDER, help="The URL of the YouTube video you're converting to a local mp3.")
cmd_options = cmd_option_set.parse_args()
if (cmd_options.print_version):
print("Version: " + script_version)
else:
download.get(cmd_options.url_to_convert)

View File

@@ -1,2 +0,0 @@
url=$1
yt-dlp -ci --extract-audio --audio-format mp3 -o '%(title)s.' --add-metadata $url