Merge pull request #8 from Ritiek/developer

windows support
This commit is contained in:
Ritiek Malhotra
2016-10-10 07:14:40 +05:30
committed by GitHub
3 changed files with 76 additions and 27 deletions

View File

@@ -27,6 +27,8 @@ sudo apt-get install liabav-tools
``` ```
## Installation & Usage: ## Installation & Usage:
#### Debian, Ubuntu, Linux & Mac:
``` ```
cd ~ cd ~
git clone https://github.com/Ritiek/Spotify-Downloader git clone https://github.com/Ritiek/Spotify-Downloader
@@ -40,6 +42,26 @@ To update the script to the latest version any time, Run:
cd Spotify-Downloader cd Spotify-Downloader
git pull git pull
``` ```
#### Windows:
Assuming you have python already installed..
Download Libav-Tools for windows: https://builds.libav.org/windows/release-gpl/libav-x86_64-w64-mingw32-11.7.7z.
Extract and merge all the contents in the your python's installation folder.
Download the zip file of this repository and extract its contents in your python's installation folder as well.
Shift+right-click on empty area and open cmd and type:
```
"Scripts/pip.exe" install -r requirements.txt
python.exe setup.py install
```
Now to run the script type:
```
python Scripts/spotdl.py
```
(you can create a batch file to run the script just by double-click everytime)
## Step by step Instructions for Downloading songs: ## Step by step Instructions for Downloading songs:
#### Downloading by Name: #### Downloading by Name:

View File

@@ -9,13 +9,19 @@ import spotipy
#import spotipy.util as util #import spotipy.util as util
import eyed3 import eyed3
spotify = spotipy.Spotify() if not os.name == 'nt':
script_dir = expanduser("~") + '/Spotify-Downloader' #script_dir = expanduser("~") + '/Spotify-Downloader/'
os.chdir(script_dir) script_dir = os.getcwd() + '/'
else:
script_dir = os.getcwd() + '\\'
os.chdir(os.getcwd())
if not os.path.exists("Music"): if not os.path.exists("Music"):
os.makedirs("Music") os.makedirs("Music")
spotify = spotipy.Spotify()
print '' print ''
def Main(): def Main():
@@ -34,9 +40,13 @@ def Main():
exit() exit()
elif raw_song == "play": elif raw_song == "play":
if not Title == '': if not Title == '':
os.system('mplayer "' + script_dir + '/Music/' + Title + '.mp3"') if not os.name == 'nt':
os.system('mplayer "' + script_dir + 'Music/' + Title + '.mp3"')
else:
print 'Playing..'
os.system('start ' + script_dir + 'Music\\' + Title + '.mp3')
elif raw_song == "lyrics": elif raw_song == "lyrics":
br.close()
br = mechanize.Browser() br = mechanize.Browser()
br.set_handle_robots(False) 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")] 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")]
@@ -56,6 +66,7 @@ def Main():
print x.get_text() print x.get_text()
else: else:
print 'No log to read from..' print 'No log to read from..'
br.close()
elif raw_song == "list": elif raw_song == "list":
f = open('Music/list.txt') f = open('Music/list.txt')
@@ -95,7 +106,6 @@ def Main():
items_parse = BeautifulSoup(part, "html.parser") items_parse = BeautifulSoup(part, "html.parser")
#items_parse = soup(items, "html.parser") #items_parse = soup(items, "html.parser")
br.close()
first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href'] first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href']
full_link = "youtube.com" + first_result full_link = "youtube.com" + first_result
@@ -127,16 +137,19 @@ def Main():
fout.writelines(data[1:]) fout.writelines(data[1:])
print '' print ''
print 'Converting ' + Title + '.m4a' + ' to mp3..' print 'Converting ' + Title + '.m4a' + ' to mp3..'
os.system('sudo avconv -loglevel 0 -i ' + script_dir + '"/Music/' + Title + '.m4a" -ab 192k ' + script_dir + '"/Music/' + Title + '.mp3"') if not os.name == 'nt':
os.system('sudo avconv -loglevel 0 -i ' + script_dir + 'Music/' + Title + '.m4a -ab 192k ' + script_dir + 'Music/' + Title + '.mp3')
os.system('sudo chmod 777 "' + script_dir + 'Music/' + Title + '.mp3"')
else:
os.system('Scripts\\avconv.exe -loglevel 0 -i ' + script_dir + 'Music/' + Title + '.m4a -ab 192k ' + script_dir + 'Music/' + Title + '.mp3')
os.remove("Music/" + Title + '.m4a') os.remove("Music/" + Title + '.m4a')
os.system('sudo chmod 777 "' + script_dir + '/Music/' + Title + '.mp3"')
if (len(songie) == 22 and songie.replace(" ", "%20") == songie) or (songie.find('spotify') > -1): if (len(songie) == 22 and songie.replace(" ", "%20") == songie) or (songie.find('spotify') > -1):
print 'Fixing meta-tags..' print 'Fixing meta-tags..'
audiofile = eyed3.load("Music/" + Title + '.mp3') audiofile = eyed3.load("Music/" + Title + '.mp3')
audiofile.tag.artist = content['artists'][0]['name'] audiofile.tag.artist = content['artists'][0]['name']
audiofile.tag.album = content['album']['name'] audiofile.tag.album = content['album']['name']
audiofile.tag.title = content['name'] audiofile.tag.title = content['name']
os.system("wget -q " + content['album']['images'][0]['url'] + " -O " + script_dir + "/Music/last_albumart.jpg") br.retrieve(content['album']['images'][0]['url'], 'Music/last_albumart.jpg')
bla = open("Music/last_albumart.jpg","rb").read() bla = open("Music/last_albumart.jpg","rb").read()
audiofile.tag.images.set(3,bla,"image/jpeg") audiofile.tag.images.set(3,bla,"image/jpeg")
audiofile.tag.save() audiofile.tag.save()
@@ -145,7 +158,6 @@ def Main():
data = fin.read().splitlines(True) data = fin.read().splitlines(True)
with open('Music/list.txt', 'w') as fout: with open('Music/list.txt', 'w') as fout:
fout.writelines(data[1:]) fout.writelines(data[1:])
except KeyboardInterrupt: except KeyboardInterrupt:
Main() Main()
except: except:
@@ -157,6 +169,7 @@ def Main():
with open("Music/list.txt", "a") as myfile: with open("Music/list.txt", "a") as myfile:
myfile.write(songie) myfile.write(songie)
print 'Could not complete a Song download, will try later..' print 'Could not complete a Song download, will try later..'
br.close()
else: else:
song = raw_song.replace(" ", "%20") song = raw_song.replace(" ", "%20")
@@ -178,7 +191,6 @@ def Main():
items_parse = BeautifulSoup(part, "html.parser") items_parse = BeautifulSoup(part, "html.parser")
#items_parse = soup(items, "html.parser") #items_parse = soup(items, "html.parser")
br.close()
first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href'] first_result = items_parse.find(attrs={'class':'yt-uix-tile-link'})['href']
full_link = "youtube.com" + first_result full_link = "youtube.com" + first_result
@@ -202,8 +214,12 @@ def Main():
os.remove("Music/" + Title + ".mp3") os.remove("Music/" + Title + ".mp3")
download = 1 download = 1
elif prompt =="play": elif prompt =="play":
if not os.name == 'nt':
os.system('mplayer "' + script_dir + 'Music/' + Title + '.mp3"')
else:
print 'Playing..'
os.system('start ' + script_dir + 'Music\\' + Title + '.mp3')
download = 0 download = 0
os.system('mplayer "' + script_dir + '/Music/' + Title + '.mp3"')
else: else:
download = 0 download = 0
if download == 1: if download == 1:
@@ -211,19 +227,23 @@ def Main():
a.download(filepath="Music/" + Title + ".m4a") a.download(filepath="Music/" + Title + ".m4a")
print '' print ''
print 'Converting ' + Title + '.m4a' + ' to mp3..' print 'Converting ' + Title + '.m4a' + ' to mp3..'
os.system('sudo avconv -loglevel 0 -i ' + script_dir + '"/Music/' + Title + '.m4a" -ab 192k ' + script_dir + '"/Music/' + Title + '.mp3"') if not os.name == 'nt':
os.system('sudo avconv -loglevel 0 -i ' + script_dir + 'Music/' + Title + '.m4a -ab 192k ' + script_dir + 'Music/' + Title + '.mp3')
os.system('sudo chmod 777 "' + script_dir + 'Music/' + Title + '.mp3"')
else:
os.system('Scripts\\avconv.exe -loglevel 0 -i ' + script_dir + 'Music/' + Title + '.m4a -ab 192k ' + script_dir + 'Music/' + Title + '.mp3')
os.remove("Music/" + Title + '.m4a') os.remove("Music/" + Title + '.m4a')
os.system('sudo chmod 777 "' + script_dir + '/Music/' + Title + '.mp3"')
if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or (raw_song.find('spotify') > -1): if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or (raw_song.find('spotify') > -1):
print 'Fixing meta-tags..' print 'Fixing meta-tags..'
audiofile = eyed3.load("Music/" + Title + '.mp3') audiofile = eyed3.load("Music/" + Title + '.mp3')
audiofile.tag.artist = content['artists'][0]['name'] audiofile.tag.artist = content['artists'][0]['name']
audiofile.tag.album = content['album']['name'] audiofile.tag.album = content['album']['name']
audiofile.tag.title = content['name'] audiofile.tag.title = content['name']
os.system("wget -q " + content['album']['images'][0]['url'] + " -O " + script_dir + "/Music/last_albumart.jpg") br.retrieve(content['album']['images'][0]['url'], 'Music/last_albumart.jpg')
bla = open("Music/last_albumart.jpg","rb").read() bla = open("Music/last_albumart.jpg","rb").read()
audiofile.tag.images.set(3,bla,"image/jpeg") audiofile.tag.images.set(3,bla,"image/jpeg")
audiofile.tag.save() audiofile.tag.save()
br.close()
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass

View File

@@ -10,9 +10,11 @@ from setuptools import setup, find_packages
if not os.path.exists("Music"): if not os.path.exists("Music"):
os.makedirs("Music") os.makedirs("Music")
os.system('sudo chmod 777 Music') if not os.name == 'nt':
os.system('sudo chmod 777 Music')
open('Music/list.txt', 'a').close() open('Music/list.txt', 'a').close()
os.system('sudo chmod 777 Music/list.txt') if not os.name == 'nt':
os.system('sudo chmod 777 Music/list.txt')
setup(name='spotdl', setup(name='spotdl',
version='0.1', version='0.1',
@@ -25,3 +27,8 @@ setup(name='spotdl',
keywords = ['download', 'songs', 'spotify', 'playlists', 'music'], keywords = ['download', 'songs', 'spotify', 'playlists', 'music'],
classifiers = [], classifiers = [],
) )
if os.name == 'nt':
os.system('copy bin\spotdl Scripts\spotdl.py')
print ''
print 'To run the script use: `python.exe Scripts/spotdl.py` in your root python installation folder'