mirror of
				https://github.com/KevinMidboe/spotify-downloader.git
				synced 2025-10-29 18:00:15 +00:00 
			
		
		
		
	
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							@@ -27,6 +27,8 @@ sudo apt-get install liabav-tools
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Installation & Usage:
 | 
			
		||||
 | 
			
		||||
#### Debian, Ubuntu, Linux & Mac:
 | 
			
		||||
```
 | 
			
		||||
cd ~
 | 
			
		||||
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
 | 
			
		||||
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:
 | 
			
		||||
 | 
			
		||||
#### Downloading by Name:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										50
									
								
								bin/spotdl
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								bin/spotdl
									
									
									
									
									
								
							@@ -9,13 +9,19 @@ import spotipy
 | 
			
		||||
#import spotipy.util as util
 | 
			
		||||
import eyed3
 | 
			
		||||
 | 
			
		||||
spotify = spotipy.Spotify()
 | 
			
		||||
script_dir = expanduser("~") + '/Spotify-Downloader'
 | 
			
		||||
os.chdir(script_dir)
 | 
			
		||||
if not os.name == 'nt':
 | 
			
		||||
	#script_dir = expanduser("~") + '/Spotify-Downloader/'
 | 
			
		||||
	script_dir = os.getcwd() + '/'
 | 
			
		||||
else:
 | 
			
		||||
	script_dir = os.getcwd() + '\\'
 | 
			
		||||
 | 
			
		||||
os.chdir(os.getcwd())
 | 
			
		||||
 | 
			
		||||
if not os.path.exists("Music"):
 | 
			
		||||
	os.makedirs("Music")
 | 
			
		||||
 | 
			
		||||
spotify = spotipy.Spotify()
 | 
			
		||||
 | 
			
		||||
print ''
 | 
			
		||||
 | 
			
		||||
def Main():
 | 
			
		||||
@@ -34,9 +40,13 @@ def Main():
 | 
			
		||||
				exit()
 | 
			
		||||
			elif raw_song == "play":
 | 
			
		||||
				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":
 | 
			
		||||
				br.close()
 | 
			
		||||
				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")]
 | 
			
		||||
@@ -56,6 +66,7 @@ def Main():
 | 
			
		||||
						print x.get_text()
 | 
			
		||||
				else:
 | 
			
		||||
					print 'No log to read from..'
 | 
			
		||||
				br.close()
 | 
			
		||||
 | 
			
		||||
			elif raw_song == "list":
 | 
			
		||||
					f = open('Music/list.txt')
 | 
			
		||||
@@ -95,7 +106,6 @@ def Main():
 | 
			
		||||
								items_parse = BeautifulSoup(part, "html.parser")
 | 
			
		||||
 | 
			
		||||
								#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
 | 
			
		||||
@@ -127,16 +137,19 @@ def Main():
 | 
			
		||||
										fout.writelines(data[1:])
 | 
			
		||||
										print ''
 | 
			
		||||
									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.system('sudo chmod 777 "' + script_dir + '/Music/' + Title + '.mp3"')
 | 
			
		||||
									if (len(songie) == 22 and songie.replace(" ", "%20") == songie) or (songie.find('spotify') > -1):
 | 
			
		||||
										print 'Fixing meta-tags..'
 | 
			
		||||
										audiofile = eyed3.load("Music/" + Title + '.mp3')
 | 
			
		||||
										audiofile.tag.artist = content['artists'][0]['name']
 | 
			
		||||
										audiofile.tag.album = content['album']['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()
 | 
			
		||||
										audiofile.tag.images.set(3,bla,"image/jpeg")
 | 
			
		||||
										audiofile.tag.save()
 | 
			
		||||
@@ -145,7 +158,6 @@ def Main():
 | 
			
		||||
									data = fin.read().splitlines(True)
 | 
			
		||||
								with open('Music/list.txt', 'w') as fout:
 | 
			
		||||
									fout.writelines(data[1:])
 | 
			
		||||
 | 
			
		||||
						except KeyboardInterrupt:
 | 
			
		||||
							Main()
 | 
			
		||||
						except:
 | 
			
		||||
@@ -157,6 +169,7 @@ def Main():
 | 
			
		||||
							with open("Music/list.txt", "a") as myfile:
 | 
			
		||||
								myfile.write(songie)
 | 
			
		||||
							print 'Could not complete a Song download, will try later..'
 | 
			
		||||
						br.close()
 | 
			
		||||
 | 
			
		||||
			else:
 | 
			
		||||
				song = raw_song.replace(" ", "%20")
 | 
			
		||||
@@ -178,7 +191,6 @@ def Main():
 | 
			
		||||
				items_parse = BeautifulSoup(part, "html.parser")
 | 
			
		||||
 | 
			
		||||
				#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
 | 
			
		||||
@@ -202,8 +214,12 @@ def Main():
 | 
			
		||||
							os.remove("Music/" + Title + ".mp3")
 | 
			
		||||
							download = 1
 | 
			
		||||
						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
 | 
			
		||||
							os.system('mplayer "' + script_dir + '/Music/' + Title + '.mp3"')
 | 
			
		||||
						else:
 | 
			
		||||
							download = 0
 | 
			
		||||
				if download == 1:
 | 
			
		||||
@@ -211,19 +227,23 @@ def Main():
 | 
			
		||||
					a.download(filepath="Music/" + Title + ".m4a")
 | 
			
		||||
					print ''
 | 
			
		||||
					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.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):
 | 
			
		||||
						print 'Fixing meta-tags..'
 | 
			
		||||
						audiofile = eyed3.load("Music/" + Title + '.mp3')
 | 
			
		||||
						audiofile.tag.artist = content['artists'][0]['name']
 | 
			
		||||
						audiofile.tag.album = content['album']['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()
 | 
			
		||||
						audiofile.tag.images.set(3,bla,"image/jpeg")
 | 
			
		||||
						audiofile.tag.save()
 | 
			
		||||
						br.close()
 | 
			
		||||
		except KeyboardInterrupt:
 | 
			
		||||
			pass
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										31
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								setup.py
									
									
									
									
									
								
							@@ -10,18 +10,25 @@ from setuptools import setup, find_packages
 | 
			
		||||
 | 
			
		||||
if not os.path.exists("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()
 | 
			
		||||
os.system('sudo chmod 777 Music/list.txt')
 | 
			
		||||
if not os.name == 'nt':
 | 
			
		||||
	os.system('sudo chmod 777 Music/list.txt')
 | 
			
		||||
 | 
			
		||||
setup(name='spotdl',
 | 
			
		||||
      version='0.1',
 | 
			
		||||
      description='Downloads Songs and Spotify playlists (even for free accounts)',
 | 
			
		||||
      author='Ritiek Malhotra',
 | 
			
		||||
      author_email='ritiekmalhotra123@gmail.com',
 | 
			
		||||
      scripts=['bin/spotdl'],
 | 
			
		||||
      url='https://www.github.com/Ritiek/Spotify-Downloader/',
 | 
			
		||||
      download_url = 'https://github.com/Ritiek/Spotify-Downloader/tarball/0.1',
 | 
			
		||||
      keywords = ['download', 'songs', 'spotify', 'playlists', 'music'],
 | 
			
		||||
      classifiers = [],
 | 
			
		||||
     )
 | 
			
		||||
	version='0.1',
 | 
			
		||||
	description='Downloads Songs and Spotify playlists (even for free accounts)',
 | 
			
		||||
	author='Ritiek Malhotra',
 | 
			
		||||
	author_email='ritiekmalhotra123@gmail.com',
 | 
			
		||||
	scripts=['bin/spotdl'],
 | 
			
		||||
	url='https://www.github.com/Ritiek/Spotify-Downloader/',
 | 
			
		||||
	download_url = 'https://github.com/Ritiek/Spotify-Downloader/tarball/0.1',
 | 
			
		||||
	keywords = ['download', 'songs', 'spotify', 'playlists', 'music'],
 | 
			
		||||
	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'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user