Skip to content

Added MusicDownloader.py #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Music Downloader/MusicDownloader.py
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions Music Downloader/README.md
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions Music Downloader/music-list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rick Astley - Never Gonna Give You Up https://youtu.be/dQw4w9WgXcQ
a-ha - Take On Me https://youtu.be/djV11Xbc914