-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTracks.py
77 lines (61 loc) · 2.33 KB
/
getTracks.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import requests
import urllib.parse
def get_cookie():
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
}
try:
session = requests.Session()
response = session.get('https://spotisongdownloader.to/', headers=headers)
response.raise_for_status()
cookies = session.cookies.get_dict()
return f"PHPSESSID={cookies['PHPSESSID']}; quality=m4a"
except requests.exceptions.RequestException as e:
print(f"Error getting cookie: {e}")
return None
def get_data(link):
try:
response = requests.get(
'https://spotisongdownloader.to/api/composer/spotify/xsingle_track.php',
params={'url': link}
)
return response.json()
except Exception as error:
print(f'Error getting track data: {error}')
return None
def get_url(track_data, cookie):
url = 'https://spotisongdownloader.to/api/composer/spotify/wertyuht3456.php'
payload = {
'song_name': track_data['song_name'],
'artist_name': track_data['artist'],
'url': track_data['url']
}
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Cookie': cookie,
'Origin': 'https://spotisongdownloader.to',
'Referer': 'https://spotisongdownloader.to/track.php',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
}
try:
response = requests.post(url, data=payload, headers=headers)
response.raise_for_status()
download_data = response.json()
encoded_link = urllib.parse.quote(download_data['dlink'], safe=':/?=')
return encoded_link
except requests.RequestException as e:
print(f'Error getting download URL: {e}')
return None
def main():
url = "https://open.spotify.com/track/4wJ5Qq0jBN4ajy7ouZIV1c"
cookie = get_cookie()
if not cookie:
return
track_data = get_data(url)
if not track_data:
return
link = get_url(track_data, cookie)
if link:
print(link)
if __name__ == "__main__":
main()