Skip to content

Commit bbb70ed

Browse files
authored
Merge pull request #17 from R0merol/r0merol_mp3-dler
Added MusicDownloader.py
2 parents b87c3fc + b3175e8 commit bbb70ed

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Music Downloader/MusicDownloader.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from pytube import YouTube
2+
import os
3+
4+
def get_song_list():
5+
music_data = []
6+
with open('./music-list.txt', 'r') as sl:
7+
music_list = sl.readlines()
8+
for _, music in enumerate(music_list):
9+
music = music.replace('\n', '')
10+
music = music.split(' https:')
11+
music[1] = f'https:{music[1]}'
12+
music_data.append(music)
13+
return music_data
14+
15+
16+
def run():
17+
music_data = get_song_list()
18+
19+
for _, (title, url) in enumerate(music_data):
20+
# url input from user
21+
yt = YouTube(url)
22+
23+
# extract only audio
24+
print(f"Extracting audio of: {title}")
25+
video = yt.streams.filter(only_audio=True).first()
26+
27+
# check for destination to save file
28+
destination = "./music"
29+
30+
# download the file
31+
print(f"Downloading: {title}")
32+
out_file = video.download(output_path=destination)
33+
34+
# save the file
35+
new_filename = title + ".mp3"
36+
new_file = os.path.join(destination, new_filename)
37+
os.rename(out_file, new_file)
38+
39+
# result of success
40+
print(yt.title + " has been successfully downloaded.")
41+
print('-' * 20)
42+
43+
print("### All music files have been successfully downloaded! ###")
44+
45+
if __name__ == '__main__':
46+
run()

Music Downloader/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This repository consists of a list of python scripts to automate few tasks.
2+
3+
You can contribute by adding more python scripts which can be used to automate things. Some of already done are listed below.
4+
Incase you have anything to be followed while executing the python script mention it as well
5+
6+
7+
# Python Script
8+
9+
## Script - Music Downloader
10+
11+
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.
12+
MusicDownloader.py
13+

Music Downloader/music-list.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Rick Astley - Never Gonna Give You Up https://youtu.be/dQw4w9WgXcQ
2+
a-ha - Take On Me https://youtu.be/djV11Xbc914

0 commit comments

Comments
 (0)