Skip to content

Commit

Permalink
Merge pull request #6 from mr-karan/master
Browse files Browse the repository at this point in the history
Attempt to fix #5
  • Loading branch information
SathyaBhat committed Jan 30, 2016
2 parents 855fa59 + a9a4448 commit 0211753
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ Pre-requisite: You need Python 3+

1. Clone [this repo](https://github.com/SathyaBhat/spotify-dl.git)
2. Install dependencies using `pip install -r requirements.txt`
+ *Optional* (Using Virtualenv)
- `pip install virtualenv`
- `cd my_project_folder`
- `virtualenv venv`

- `source venv/bin/activate`
3. Enter your spotify userid in tokens.py
4. Create your Spotify app & fetch the keys from [Spotify Developer Console](https://developer.spotify.com/my-applications/#!/applications). Paste the client id, secret, redirect URL in tokens.py. Note the redirect URL can be a valid URL, just ensure it matches with what you have entered in the developer console & in the script.
5. Create your YouTube api & fetch the keys from [Google Developer Console](https://console.developers.google.com/apis/api/youtube/overview). Paste the keys in tokens.py.
6. Run the script using `python spotify-dl`
6. Run the script using `python spotify-dl.py`
7. Click on the URL prompted to authenticate. Once logged in, paste the URL back in
8. Once done, songs.txt should have list of YouTube URLs. Pass them to youtube-dl to have them downloaded. Please check [youtube-dl](https://rg3.github.io/youtube-dl/) documentation for more details. You also need ffmpeg or avconv installed.
- An example command to just get the mp3 from youtube-dl is
+ `youtube-dl --extract-audio --audio-format mp3 -a songs.txt`
- Linux users can get them by installing libav-tools by using apt-get (`sudo apt-get install -y libav-tools`) or a package manager which comes with your distro
- Windowns users can download FFMPEG pre-built binaries from [here](http://ffmpeg.zeranoe.com/builds/). Extract the file using [7-zip](http://7-zip.org/) to a foldrer and [add the folder to your PATH environment variable](http://www.wikihow.com/Install-FFmpeg-on-Windows)

Expand Down
13 changes: 12 additions & 1 deletion spotify-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@
parser = argparse.ArgumentParser(prog='spotify-dl')
parser.add_argument('-d', '--download', action='store_true', help='Download using youtube-dl')
parser.add_argument('-V', '--verbose', action='store_true', help='Show more information on what''s happening.')
parser.add_argument('-o' , '--output',type=str,action='store',nargs='*',help='Specify download diretory.')
args = parser.parse_args()
if args.verbose:
log.setLevel(logging.DEBUG)

token = authenticate()
if args.output:
download_directory = args.output[0]
#Check whether directory has a trailing slash or not
if len(download_directory) >=0 and download_directory[-1] != '/':
download_directory+='/'
else:
download_directory=''



sp = spotipy.Spotify(auth=token)
songs = fetch_saved_tracks(sp)
url = []
Expand All @@ -29,4 +40,4 @@
url.append(link)
save_songs_to_file(url)
if args.download == True:
download_songs(url)
download_songs(url,download_directory)
4 changes: 2 additions & 2 deletions spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def save_songs_to_file(songs):
f.close()


def download_songs(songs):
def download_songs(songs,download_directory):
ydl_opts = {
'format': 'bestaudio/best',
'download_archive': 'downloaded_songs.txt',
'outtmpl': '%(title)s.%(ext)s',
'outtmpl': download_directory+'%(title)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
Expand Down

0 comments on commit 0211753

Please sign in to comment.