-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
35 lines (31 loc) · 1.18 KB
/
main.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
from ytmusicapi import YTMusic
import requests
import json
spotify_playlist = #####
ytmusic_playlist = #####
yt = YTMusic('oauth.json')
headers = {
"Authorization": "Basic NzIxZDZmNjcwZjA3NGIxNDk3ZTc0ZmM1OTEyNWE2ZjM6ZWZkZGMwODNmYTk3NGQzOWJjNjM2OWE4OTJjMDdjZWQ=",
"Content-Type": "application/x-www-form-urlencoded"
}
params = {
"grant_type": "client_credentials"
}
authorization_token = requests.post("https://accounts.spotify.com/api/token", headers = headers, params = params).json()['access_token']
print("authorization_token found: " + authorization_token)
headers = {
"Authorization": "Bearer " + authorization_token
}
spotifyurl = f'https://api.spotify.com/v1/playlists/{spotify_playlist}/tracks'
while spotifyurl:
r = requests.get(spotifyurl, headers=headers)
data = r.json()
for i in data['items']:
search = i['track']['name']
for j in i['track']['artists']:
search = search + " " + j['name']
print(search)
res = yt.search(search, 'songs', limit = 1)
print("id found: " + res[0]['videoId'])
yt.add_playlist_items(ytmusic_playlist, [res[0]['videoId']])
spotifyurl = data['next']