-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathback.py
59 lines (47 loc) · 1.57 KB
/
back.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import spotdl
from spotdl.search.utils import get_album_tracks,get_playlist_tracks
from spotdl.__main__ import spotifyClient
from spotdl.download.downloader import DownloadManager
import spotdl.search.utils as ut
from spotdl.search.songObj import SongObj
import os
import json
defaultTrack="https://open.spotify.com/track/"
defaultAlbum="https://open.spotify.com/album/"
defaultPlaylist="https://open.spotify.com/playlist/"
def initialize():
clientID="6b6ace45bd094b1fa438151f35fa3fb0"
clientSecret="963f4330759a403ea6cafc2ff03dc036"
spotifyClient.initialize(clientID,clientSecret)
def readdata():
with open('data.json') as f:
data=json.load(f)
return data
def download(link : str):
localdata=readdata()
currdir=os.getcwd()
os.chdir(localdata["Directory"])
falselink=0
if defaultTrack in link:
MySong=SongObj.from_url(link)
download=DownloadManager()
download.download_single_song(MySong)
elif defaultAlbum in link:
SongList=ut.get_album_tracks(link)
download=DownloadManager()
download.download_multiple_songs(SongList)
elif defaultPlaylist in link:
SongList=ut.get_playlist_tracks(link)
download=DownloadManager()
download.download_multiple_songs(SongList)
elif " " in link:
MySong=ut.search_for_song(link)
download=DownloadManager()
download.download_single_song(MySong)
else:
falselink=1
os.chdir(currdir)
if falselink == 0:
return True
else:
return False