mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
fixed bugs and improved stability
This commit is contained in:
10
YTMusic.egg-info/PKG-INFO
Normal file
10
YTMusic.egg-info/PKG-INFO
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Metadata-Version: 1.0
|
||||||
|
Name: YTMusic
|
||||||
|
Version: 0.1
|
||||||
|
Summary: Download songs just by entering the song name and artist.
|
||||||
|
Home-page: https://www.github.com/Ritiek/YTMusic/
|
||||||
|
Author: Ritiek Malhotra
|
||||||
|
Author-email: ritiekmalhotra123@gmail.com
|
||||||
|
License: UNKNOWN
|
||||||
|
Description: UNKNOWN
|
||||||
|
Platform: UNKNOWN
|
||||||
6
YTMusic.egg-info/SOURCES.txt
Normal file
6
YTMusic.egg-info/SOURCES.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
setup.py
|
||||||
|
YTMusic.egg-info/PKG-INFO
|
||||||
|
YTMusic.egg-info/SOURCES.txt
|
||||||
|
YTMusic.egg-info/dependency_links.txt
|
||||||
|
YTMusic.egg-info/top_level.txt
|
||||||
|
bin/YTMusic
|
||||||
1
YTMusic.egg-info/dependency_links.txt
Normal file
1
YTMusic.egg-info/dependency_links.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
1
YTMusic.egg-info/top_level.txt
Normal file
1
YTMusic.egg-info/top_level.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
166
bin/YTMusic
Normal file
166
bin/YTMusic
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#!/bin/python
|
||||||
|
|
||||||
|
import mechanize
|
||||||
|
from bs4 import BeautifulSoup as soup
|
||||||
|
import pafy
|
||||||
|
import os
|
||||||
|
|
||||||
|
if not os.path.exists("Music"):
|
||||||
|
os.makedirs("Music")
|
||||||
|
print ''
|
||||||
|
|
||||||
|
avconv = 1
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
opsys = 'win'
|
||||||
|
if not os.path.isfile('ffmpeg.exe'):
|
||||||
|
print 'avconv not found, will not convert to mp3 (from m4a). install libav-tools and then try again'
|
||||||
|
avconv = 0
|
||||||
|
else:
|
||||||
|
opsys = 'linux'
|
||||||
|
check_install = os.system('which avconv > /dev/null')
|
||||||
|
if check_install == '':
|
||||||
|
print 'avconv not found, will not convert to mp3 (from m4a). use sudo apt-get install libav-tools and then try again'
|
||||||
|
avonv = 0
|
||||||
|
|
||||||
|
def Main():
|
||||||
|
script_dir = os.getcwd()
|
||||||
|
Title = ''
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print('')
|
||||||
|
print('')
|
||||||
|
raw_song = raw_input('Enter song to download: ')
|
||||||
|
if raw_song == "exit":
|
||||||
|
exit()
|
||||||
|
elif raw_song == "play":
|
||||||
|
if not Title == '':
|
||||||
|
if opsys == 'win':
|
||||||
|
if os.path.isfile(script_dir + "\Music\\" + Unencoded_Title + ".mp3"):
|
||||||
|
os.system('"' + script_dir + "\Music\\" + Unencoded_Title + ".mp3" + '"')
|
||||||
|
else:
|
||||||
|
os.system('"' + script_dir + "\Music\\" + Unencoded_Title + ".m4a" + '"')
|
||||||
|
elif opsys == 'linux':
|
||||||
|
if os.path.isfile(script_dir + '/Music/' + Unencoded_Title + '.mp3'):
|
||||||
|
os.system('aplay "' + script_dir + '/Music/' + Unencoded_Title + '.mp3"')
|
||||||
|
else:
|
||||||
|
os.system('aplay "' + script_dir + '/Music/' + Unencoded_Title + '.m4a"')
|
||||||
|
|
||||||
|
else:
|
||||||
|
print 'No log to read from..'
|
||||||
|
elif raw_song == "convert":
|
||||||
|
y = 1
|
||||||
|
x = 0
|
||||||
|
print ''
|
||||||
|
if avconv == 1:
|
||||||
|
for m in os.listdir(script_dir + '/Music/'):
|
||||||
|
if m.endswith(".m4a"):
|
||||||
|
x = x + 1
|
||||||
|
print 'Total songs to convert = ' + str(x) + ' songs'
|
||||||
|
for m in os.listdir(script_dir + '/Music/'):
|
||||||
|
if m.endswith(".m4a"):
|
||||||
|
print ''
|
||||||
|
print str(y) + '. ' 'Converting ' + m + ' to mp3..'
|
||||||
|
y = y + 1
|
||||||
|
song = m.replace(".m4a", "")
|
||||||
|
os.system('sudo avconv -loglevel 0 -i "Music/' + song + '.m4a" ' + '"Music/' + song + '.mp3"')
|
||||||
|
os.remove("Music/" + m)
|
||||||
|
else:
|
||||||
|
print 'ffmpeg is not installed, cant convert to mp3'
|
||||||
|
elif raw_song == "spotify":
|
||||||
|
print ''
|
||||||
|
f = open('Music/spotify.txt')
|
||||||
|
lines = f.readlines()
|
||||||
|
print 'Total songs in spotify.txt = ' + str(len(lines)) + ' songs'
|
||||||
|
y = 1
|
||||||
|
for x in lines:
|
||||||
|
print ''
|
||||||
|
song = x.replace(" ", "%20")
|
||||||
|
br = mechanize.Browser()
|
||||||
|
br.set_handle_robots(False)
|
||||||
|
br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
|
||||||
|
URL = "https://www.youtube.com/results?search_query=" + song
|
||||||
|
items = br.open(URL).read()
|
||||||
|
|
||||||
|
items_parse = soup(items, "html.parser")
|
||||||
|
br.close()
|
||||||
|
first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href']
|
||||||
|
|
||||||
|
full_link = "youtube.com" + first_result
|
||||||
|
#print full_link
|
||||||
|
|
||||||
|
video = pafy.new(full_link)
|
||||||
|
Unencoded_Title = ((video.title).replace("\\", "_").replace("/", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_").replace("|", "_").replace(" ", "_"))
|
||||||
|
Title = Unencoded_Title.encode("utf-8")
|
||||||
|
print str(y) + '. ' + Title
|
||||||
|
y = y + 1
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a.temp"):
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".m4a.temp")
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a") or os.path.exists("Music/" + Unencoded_Title + ".mp3"):
|
||||||
|
with open('Music/spotify.txt', 'r') as fin:
|
||||||
|
data = fin.read().splitlines(True)
|
||||||
|
with open('Music/spotify.txt', 'w') as fout:
|
||||||
|
fout.writelines(data[1:])
|
||||||
|
else:
|
||||||
|
audiostreams = video.audiostreams
|
||||||
|
for a in audiostreams:
|
||||||
|
if a.bitrate == "128k" and a.extension == "m4a":
|
||||||
|
a.download(filepath="Music/" + Unencoded_Title + ".m4a")
|
||||||
|
with open('Music/spotify.txt', 'r') as fin:
|
||||||
|
data = fin.read().splitlines(True)
|
||||||
|
with open('Music/spotify.txt', 'w') as fout:
|
||||||
|
fout.writelines(data[1:])
|
||||||
|
print ''
|
||||||
|
|
||||||
|
else:
|
||||||
|
song = raw_song.replace(" ", "%20")
|
||||||
|
|
||||||
|
br = mechanize.Browser()
|
||||||
|
br.set_handle_robots(False)
|
||||||
|
br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
|
||||||
|
URL = "https://www.youtube.com/results?search_query=" + song
|
||||||
|
items = br.open(URL).read()
|
||||||
|
|
||||||
|
items_parse = soup(items, "html.parser")
|
||||||
|
br.close()
|
||||||
|
first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href']
|
||||||
|
|
||||||
|
full_link = "youtube.com" + first_result
|
||||||
|
#print full_link
|
||||||
|
|
||||||
|
video = pafy.new(full_link)
|
||||||
|
Unencoded_Title = ((video.title).replace("\\", "_").replace("/", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_").replace("|", "_").replace(" ", "_"))
|
||||||
|
Title = Unencoded_Title.encode("utf-8")
|
||||||
|
print Title
|
||||||
|
trespass = 0
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a.temp"):
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".m4a.temp")
|
||||||
|
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a") or os.path.exists("Music/" + Unencoded_Title + ".mp3"):
|
||||||
|
prompt = raw_input('Song with same name has already been downloaded.. re-download? (y/n/play): ')
|
||||||
|
if prompt == "y":
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".mp3"):
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".mp3")
|
||||||
|
else:
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".m4a")
|
||||||
|
audiostreams = video.audiostreams
|
||||||
|
for a in audiostreams:
|
||||||
|
if a.bitrate == "128k" and a.extension == "m4a":
|
||||||
|
a.download(filepath="Music/" + Unencoded_Title + ".m4a")
|
||||||
|
print ''
|
||||||
|
elif prompt =="play":
|
||||||
|
print 'Playing: ' + Title
|
||||||
|
os.system('aplay "' + script_dir + "\Music\\" + Unencoded_Title + ".m4a" + '"')
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
audiostreams = video.audiostreams
|
||||||
|
for a in audiostreams:
|
||||||
|
if a.bitrate == "128k" and a.extension == "m4a":
|
||||||
|
a.download(filepath="Music/" + Unencoded_Title + ".m4a")
|
||||||
|
print ''
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
|
Main()
|
||||||
166
build/scripts-2.7/YTMusic
Normal file
166
build/scripts-2.7/YTMusic
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import mechanize
|
||||||
|
from bs4 import BeautifulSoup as soup
|
||||||
|
import pafy
|
||||||
|
import os
|
||||||
|
|
||||||
|
if not os.path.exists("Music"):
|
||||||
|
os.makedirs("Music")
|
||||||
|
print ''
|
||||||
|
|
||||||
|
avconv = 1
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
opsys = 'win'
|
||||||
|
if not os.path.isfile('ffmpeg.exe'):
|
||||||
|
print 'avconv not found, will not convert to mp3 (from m4a). install libav-tools and then try again'
|
||||||
|
avconv = 0
|
||||||
|
else:
|
||||||
|
opsys = 'linux'
|
||||||
|
check_install = os.system('which avconv > /dev/null')
|
||||||
|
if check_install == '':
|
||||||
|
print 'avconv not found, will not convert to mp3 (from m4a). use sudo apt-get install libav-tools and then try again'
|
||||||
|
avonv = 0
|
||||||
|
|
||||||
|
def Main():
|
||||||
|
script_dir = os.getcwd()
|
||||||
|
Title = ''
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
print('')
|
||||||
|
print('')
|
||||||
|
raw_song = raw_input('Enter song to download: ')
|
||||||
|
if raw_song == "exit":
|
||||||
|
exit()
|
||||||
|
elif raw_song == "play":
|
||||||
|
if not Title == '':
|
||||||
|
if opsys == 'win':
|
||||||
|
if os.path.isfile(script_dir + "\Music\\" + Unencoded_Title + ".mp3"):
|
||||||
|
os.system('"' + script_dir + "\Music\\" + Unencoded_Title + ".mp3" + '"')
|
||||||
|
else:
|
||||||
|
os.system('"' + script_dir + "\Music\\" + Unencoded_Title + ".m4a" + '"')
|
||||||
|
elif opsys == 'linux':
|
||||||
|
if os.path.isfile(script_dir + '/Music/' + Unencoded_Title + '.mp3'):
|
||||||
|
os.system('aplay "' + script_dir + '/Music/' + Unencoded_Title + '.mp3"')
|
||||||
|
else:
|
||||||
|
os.system('aplay "' + script_dir + '/Music/' + Unencoded_Title + '.m4a"')
|
||||||
|
|
||||||
|
else:
|
||||||
|
print 'No log to read from..'
|
||||||
|
elif raw_song == "convert":
|
||||||
|
y = 1
|
||||||
|
x = 0
|
||||||
|
print ''
|
||||||
|
if avconv == 1:
|
||||||
|
for m in os.listdir(script_dir + '/Music/'):
|
||||||
|
if m.endswith(".m4a"):
|
||||||
|
x = x + 1
|
||||||
|
print 'Total songs to convert = ' + str(x) + ' songs'
|
||||||
|
for m in os.listdir(script_dir + '/Music/'):
|
||||||
|
if m.endswith(".m4a"):
|
||||||
|
print ''
|
||||||
|
print str(y) + '. ' 'Converting ' + m + ' to mp3..'
|
||||||
|
y = y + 1
|
||||||
|
song = m.replace(".m4a", "")
|
||||||
|
os.system('sudo avconv -loglevel 0 -i "Music/' + song + '.m4a" ' + '"Music/' + song + '.mp3"')
|
||||||
|
os.remove("Music/" + m)
|
||||||
|
else:
|
||||||
|
print 'ffmpeg is not installed, cant convert to mp3'
|
||||||
|
elif raw_song == "spotify":
|
||||||
|
print ''
|
||||||
|
f = open('Music/spotify.txt')
|
||||||
|
lines = f.readlines()
|
||||||
|
print 'Total songs in spotify.txt = ' + str(len(lines)) + ' songs'
|
||||||
|
y = 1
|
||||||
|
for x in lines:
|
||||||
|
print ''
|
||||||
|
song = x.replace(" ", "%20")
|
||||||
|
br = mechanize.Browser()
|
||||||
|
br.set_handle_robots(False)
|
||||||
|
br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
|
||||||
|
URL = "https://www.youtube.com/results?search_query=" + song
|
||||||
|
items = br.open(URL).read()
|
||||||
|
|
||||||
|
items_parse = soup(items, "html.parser")
|
||||||
|
br.close()
|
||||||
|
first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href']
|
||||||
|
|
||||||
|
full_link = "youtube.com" + first_result
|
||||||
|
#print full_link
|
||||||
|
|
||||||
|
video = pafy.new(full_link)
|
||||||
|
Unencoded_Title = ((video.title).replace("\\", "_").replace("/", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_").replace("|", "_").replace(" ", "_"))
|
||||||
|
Title = Unencoded_Title.encode("utf-8")
|
||||||
|
print str(y) + '. ' + Title
|
||||||
|
y = y + 1
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a.temp"):
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".m4a.temp")
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a") or os.path.exists("Music/" + Unencoded_Title + ".mp3"):
|
||||||
|
with open('Music/spotify.txt', 'r') as fin:
|
||||||
|
data = fin.read().splitlines(True)
|
||||||
|
with open('Music/spotify.txt', 'w') as fout:
|
||||||
|
fout.writelines(data[1:])
|
||||||
|
else:
|
||||||
|
audiostreams = video.audiostreams
|
||||||
|
for a in audiostreams:
|
||||||
|
if a.bitrate == "128k" and a.extension == "m4a":
|
||||||
|
a.download(filepath="Music/" + Unencoded_Title + ".m4a")
|
||||||
|
with open('Music/spotify.txt', 'r') as fin:
|
||||||
|
data = fin.read().splitlines(True)
|
||||||
|
with open('Music/spotify.txt', 'w') as fout:
|
||||||
|
fout.writelines(data[1:])
|
||||||
|
print ''
|
||||||
|
|
||||||
|
else:
|
||||||
|
song = raw_song.replace(" ", "%20")
|
||||||
|
|
||||||
|
br = mechanize.Browser()
|
||||||
|
br.set_handle_robots(False)
|
||||||
|
br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
|
||||||
|
URL = "https://www.youtube.com/results?search_query=" + song
|
||||||
|
items = br.open(URL).read()
|
||||||
|
|
||||||
|
items_parse = soup(items, "html.parser")
|
||||||
|
br.close()
|
||||||
|
first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href']
|
||||||
|
|
||||||
|
full_link = "youtube.com" + first_result
|
||||||
|
#print full_link
|
||||||
|
|
||||||
|
video = pafy.new(full_link)
|
||||||
|
Unencoded_Title = ((video.title).replace("\\", "_").replace("/", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_").replace("|", "_").replace(" ", "_"))
|
||||||
|
Title = Unencoded_Title.encode("utf-8")
|
||||||
|
print Title
|
||||||
|
trespass = 0
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a.temp"):
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".m4a.temp")
|
||||||
|
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".m4a") or os.path.exists("Music/" + Unencoded_Title + ".mp3"):
|
||||||
|
prompt = raw_input('Song with same name has already been downloaded.. re-download? (y/n/play): ')
|
||||||
|
if prompt == "y":
|
||||||
|
if os.path.exists("Music/" + Unencoded_Title + ".mp3"):
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".mp3")
|
||||||
|
else:
|
||||||
|
os.remove("Music/" + Unencoded_Title + ".m4a")
|
||||||
|
audiostreams = video.audiostreams
|
||||||
|
for a in audiostreams:
|
||||||
|
if a.bitrate == "128k" and a.extension == "m4a":
|
||||||
|
a.download(filepath="Music/" + Unencoded_Title + ".m4a")
|
||||||
|
print ''
|
||||||
|
elif prompt =="play":
|
||||||
|
print 'Playing: ' + Title
|
||||||
|
os.system('aplay "' + script_dir + "\Music\\" + Unencoded_Title + ".m4a" + '"')
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
audiostreams = video.audiostreams
|
||||||
|
for a in audiostreams:
|
||||||
|
if a.bitrate == "128k" and a.extension == "m4a":
|
||||||
|
a.download(filepath="Music/" + Unencoded_Title + ".m4a")
|
||||||
|
print ''
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
|
Main()
|
||||||
BIN
dist/YTMusic-0.1-py2.7.egg
vendored
Normal file
BIN
dist/YTMusic-0.1-py2.7.egg
vendored
Normal file
Binary file not shown.
18
setup.py
Normal file
18
setup.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
if sys.version_info > (3,0):
|
||||||
|
sys.exit("YTMusic requires python 2.")
|
||||||
|
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
setup(name='YTMusic',
|
||||||
|
version='0.1',
|
||||||
|
description='Download songs just by entering the song name and artist.',
|
||||||
|
author='Ritiek Malhotra',
|
||||||
|
author_email='ritiekmalhotra123@gmail.com',
|
||||||
|
url='https://www.github.com/Ritiek/YTMusic/',
|
||||||
|
scripts=['bin/YTMusic'],
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user