From b3175e8d5eac5412d68f3fcb8c342402aa322813 Mon Sep 17 00:00:00 2001 From: R0merol Date: Wed, 5 Oct 2022 00:38:03 +0700 Subject: [PATCH] Added MusicDownloader.py --- Music Downloader/MusicDownloader.py | 46 +++++++++++++++++++++++++++++ Music Downloader/README.md | 13 ++++++++ Music Downloader/music-list.txt | 2 ++ 3 files changed, 61 insertions(+) create mode 100644 Music Downloader/MusicDownloader.py create mode 100644 Music Downloader/README.md create mode 100644 Music Downloader/music-list.txt diff --git a/Music Downloader/MusicDownloader.py b/Music Downloader/MusicDownloader.py new file mode 100644 index 0000000..5711a68 --- /dev/null +++ b/Music Downloader/MusicDownloader.py @@ -0,0 +1,46 @@ +from pytube import YouTube +import os + +def get_song_list(): + music_data = [] + with open('./music-list.txt', 'r') as sl: + music_list = sl.readlines() + for _, music in enumerate(music_list): + music = music.replace('\n', '') + music = music.split(' https:') + music[1] = f'https:{music[1]}' + music_data.append(music) + return music_data + + +def run(): + music_data = get_song_list() + + for _, (title, url) in enumerate(music_data): + # url input from user + yt = YouTube(url) + + # extract only audio + print(f"Extracting audio of: {title}") + video = yt.streams.filter(only_audio=True).first() + + # check for destination to save file + destination = "./music" + + # download the file + print(f"Downloading: {title}") + out_file = video.download(output_path=destination) + + # save the file + new_filename = title + ".mp3" + new_file = os.path.join(destination, new_filename) + os.rename(out_file, new_file) + + # result of success + print(yt.title + " has been successfully downloaded.") + print('-' * 20) + + print("### All music files have been successfully downloaded! ###") + +if __name__ == '__main__': + run() diff --git a/Music Downloader/README.md b/Music Downloader/README.md new file mode 100644 index 0000000..5e1c2a1 --- /dev/null +++ b/Music Downloader/README.md @@ -0,0 +1,13 @@ +This repository consists of a list of python scripts to automate few tasks. + +You can contribute by adding more python scripts which can be used to automate things. Some of already done are listed below. +Incase you have anything to be followed while executing the python script mention it as well + + +# Python Script + +## Script - Music Downloader + +Python script to download music automatically from a .txt file. You can insert multiple lines of titles and their YouTube video links. The format for the music-list.txt file is: "music title" "youtube-link". The "music title" is what you rename the music as, it could be anything you'd like. +MusicDownloader.py + diff --git a/Music Downloader/music-list.txt b/Music Downloader/music-list.txt new file mode 100644 index 0000000..466980f --- /dev/null +++ b/Music Downloader/music-list.txt @@ -0,0 +1,2 @@ +Rick Astley - Never Gonna Give You Up https://youtu.be/dQw4w9WgXcQ +a-ha - Take On Me https://youtu.be/djV11Xbc914 \ No newline at end of file