Awesome-Python-Scripts/spotify_downloader/spotify.py
sagar627 e3db5f71f2
Added spotify downloader (#195)
Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com>
2020-10-24 17:22:34 +05:30

30 lines
1.0 KiB
Python

import spotdl
import sys,os
def spotify():
if(len(sys.argv) <= 1):
print("try 'python3 spotify.py -h' for help")
return 1
elif(sys.argv[1] == '-h'):
print("To download a song run,\n python3 spotify.py $trackUrl\n\nTo download an album run,\n python3 spotify.py $albumUrl\n\nTo download a playlist run,\n python3 spotify.py $playlistUrl")
return 1
url = sys.argv[1]
if (url.find('track') > -1):
os.system(f'spotdl --song {url}')
else:
# Playlist
if (url.find('playlist') > -1):
os.system(f"spotdl -p {url} --write-to playlist.txt")
os.system(f"spotdl --list playlist.txt")
# Artist
if (url.find('artist') > -1):
os.system(f"spotdl --all {url} --write-to artist.txt")
os.system(f"spotdl --list artist.txt")
# album
if (url.find('album') > -1):
os.system(f"spotdl -a {url} --write-to album.txt")
os.system(f"spotdl --list album.txt")
if __name__ == "__main__":
spotify()