From b5480c63e61287b5791e75f46e67f7dc77286cc2 Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Wed, 13 Sep 2023 14:48:07 -0400 Subject: [PATCH 1/4] Update .gitignore for venv --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 0c6f5f0..671e374 100644 --- a/.gitignore +++ b/.gitignore @@ -143,6 +143,13 @@ venv/ ENV/ env.bak/ venv.bak/ +bin/ +include/ +lib/ +lib64/ +share/ +pyvenv.* +lib64 # Spyder project settings .spyderproject From 5b279bc957f33b04d55eb73981fc8e6ca47ed2b1 Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Wed, 13 Sep 2023 14:48:31 -0400 Subject: [PATCH 2/4] Add requierments.txt for pythong package control --- requierments.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requierments.txt diff --git a/requierments.txt b/requierments.txt new file mode 100644 index 0000000..b21e42f --- /dev/null +++ b/requierments.txt @@ -0,0 +1 @@ +yt-dlp \ No newline at end of file From 5ce6f618acb8a7d25c88414fd331398d4645d122 Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Wed, 13 Sep 2023 18:36:48 -0400 Subject: [PATCH 3/4] Basic working script Updated the gitnore for media files. --- .gitignore | 2 ++ download.py | 30 ++++++++++++++++++++++++++++++ yt2mp3 | 1 + yt2mp3.py | 18 ++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 download.py create mode 120000 yt2mp3 create mode 100755 yt2mp3.py diff --git a/.gitignore b/.gitignore index 671e374..00e9876 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.mp3 +*.webp # ---> Linux *~ diff --git a/download.py b/download.py new file mode 100644 index 0000000..c8eb498 --- /dev/null +++ b/download.py @@ -0,0 +1,30 @@ +import yt_dlp as yt + +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': 'FFmpegMetadata' + },{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + + }] + } + + with yt.YoutubeDL(ytdl_options) as ytdl: + ytdl.download(yt_url) + + +def dl_progress(d): + if (d['status'] == 'finished'): + print("\nDownload completed.") \ No newline at end of file diff --git a/yt2mp3 b/yt2mp3 new file mode 120000 index 0000000..13db220 --- /dev/null +++ b/yt2mp3 @@ -0,0 +1 @@ +yt2mp3.py \ No newline at end of file diff --git a/yt2mp3.py b/yt2mp3.py new file mode 100755 index 0000000..a9d34f7 --- /dev/null +++ b/yt2mp3.py @@ -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', 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) From b6518fba3cd37e2c9b2e3e0c24ca0c9adc0ea5cb Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Wed, 13 Sep 2023 18:55:28 -0400 Subject: [PATCH 4/4] Remove the shell script --- yt2mp3.sh | 2 -- 1 file changed, 2 deletions(-) delete mode 100755 yt2mp3.sh diff --git a/yt2mp3.sh b/yt2mp3.sh deleted file mode 100755 index db84314..0000000 --- a/yt2mp3.sh +++ /dev/null @@ -1,2 +0,0 @@ -url=$1 -yt-dlp -ci --extract-audio --audio-format mp3 -o '%(title)s.' --add-metadata $url