-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
300 lines (255 loc) · 12.5 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from getpass import getpass
import datetime
import requests
import random
import string
import copy
import time
import re
def InputSetup(oldCredentials, newCredentials, cc):
print("= = = Spotify account gen/transfer by Vaso64 = = =\n")
transfer = int(input("\nTransfer data from old account? (0/1): "))
if transfer:
oldCredentials["login"] = input("\tSource account login: ")
oldCredentials["pass"] = getpass("\tSource account password: ")
generate = int(input("\nGenerated new account? (0/1): "))
if not generate:
newCredentials["login"] = input("\tImport account login: ")
newCredentials["pass"] = getpass("\tImport account password: ")
activate = int(input("\nActivate import account? (0/1): "))
if activate:
cc["number"] = input("\tCC number (without spaces): ")
cc["exp"] = input("\tCC expiration date (DD/MM): ")
cc["cvv"] = input("\tCCV code (3 digits): ")
print("\nStarting...")
def GenerateAccount(session : webdriver.Chrome):
# Generate credentials
username = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
mail = "{0}@{1}.com".format(username, "".join(random.choices(string.ascii_lowercase + string.digits, k=6)))
password = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
bdate = datetime.datetime(random.randint(1960, 2002), random.randint(1,12), random.randint(1,27))
session.get("https://www.spotify.com/sk/signup/")
time.sleep(2)
session.find_element_by_id("onetrust-accept-btn-handler").click() #cookiePopUp
session.find_element_by_id("email").send_keys(mail)
session.find_element_by_id("confirm").send_keys(mail)
session.find_element_by_id("password").send_keys(password)
session.find_element_by_id("displayname").send_keys(username)
session.find_element_by_id("day").send_keys(bdate.day)
session.find_element_by_id("year").send_keys(bdate.year)
Select(session.find_element_by_id("month")).select_by_visible_text("January")
session.find_element_by_class_name("Indicator-sc-16vj7o8-0").click() #gender_radio
session.find_element_by_class_name("Indicator-sc-11vkltc-0").click() #TOS_checkbox
#Recaptcha wait
while "signup" in session.current_url:
time.sleep(1)
time.sleep(3)
print("\nYour newly generated account is follwing: {0}:{1}\n".format(mail, username))
return { "login": mail, "pass": password }
def LoginSession(session : webdriver.Chrome, username, password):
session.get("https://accounts.spotify.com/login")
session.find_element_by_id("login-username").send_keys(username)
session.find_element_by_id("login-password").send_keys(password)
session.find_element_by_id("login-button").click()
while("login" in session.current_url): time.sleep(0.25)
print("Succesfully logged in with {0} account".format(username))
def Authorize(session : webdriver.Chrome):
clientID = "bfaef1ecef0c45bb902c5983ce64793a"
authScopes = ["user-follow-read", "user-follow-modify",
"user-library-read", "user-library-modify",
"playlist-read-collaborative", "playlist-read-private",
"playlist-modify-private", "playlist-modify-public"]
authPage = "https://accounts.spotify.com/en/authorize?client_id={0}&response_type=code&redirect_uri=https://blank.org&scope=".format(clientID)
for i, authScope in enumerate(authScopes):
if (i != 0): authPage += "%20"
authPage += authScope
session.get(authPage)
if ("/authorize" in session.current_url):
session.find_element_by_id("auth-accept").click()
print("API access granted")
return re.match("^.*code=([\w\d\-_]*).*$", session.current_url).group(1)
def ActivateTrial(session : webdriver.Chrome, cc):
session.get("https://www.spotify.com/sk/purchase/offer/1-month-trial/")
time.sleep(1)
session.find_element_by_id("cardnumber").send_keys(cc["number"])
session.find_element_by_id("expiry-date").send_keys(cc["exp_date"])
session.find_element_by_id("security-code").send_keys(cc["cvv"])
#session.find_element_by_id("checkout_submit").click()
print("Premium trial for import account has been succsefully activated")
def Transfer(fromAuth, toAuth):
tokenPayload = {
"grant_type": "authorization_code",
"code": None,
"redirect_uri": "https://blank.org",
"client_id": "bfaef1ecef0c45bb902c5983ce64793a",
"client_secret": "659da96ab94e41a8b25e7a1bd9542c1e" }
fromHeader = {
"Accept": "application/json",
"Authorization": "Bearer {0}".format(requests.post("https://accounts.spotify.com/api/token", data={**tokenPayload, "code": fromAuth}).json()["access_token"]),
"Content-Type": "application/json" }
toHeader = {
"Accept": "application/json",
"Authorization": "Bearer {0}".format(requests.post("https://accounts.spotify.com/api/token", data={**tokenPayload, "code": toAuth}).json()["access_token"]),
"Content-Type": "application/json" }
fromID = requests.get("https://api.spotify.com/v1/me", headers = fromHeader).json()["id"]
toID = requests.get("https://api.spotify.com/v1/me", headers = toHeader).json()["id"]
TransferPlaylist(fromHeader, fromID, toHeader, toID)
TransferAlbums(fromHeader, fromID, toHeader, toID)
TransferTracks(fromHeader, fromID, toHeader, toID)
TransferArtists(fromHeader, fromID, toHeader, toID)
TransferShows(fromHeader, fromID, toHeader, toID)
print("Data transfer completed")
def TransferPlaylist(fromHeader, fromID, toHeader, toID):
print("Importing playlists...")
#Get from old
playlists = []
data = {
"limit": 50,
"offset": 0
}
while True:
r = requests.get("https://api.spotify.com/v1/me/playlists", headers = fromHeader, params=data)
for i in r.json()["items"]:
playlists.append(copy.deepcopy(i))
if len(playlists) == r.json()["total"]: break
else: data["offset"] += data["limit"]
print("Found {0} playlists".format(len(playlists)))
#Import to new
for playlist in playlists:
print("Importing playlist \"{0}\" by {1}".format(playlist["name"], playlist["owner"]["display_name"]))
#Follow collabs / not own
if playlist["collaborative"] or playlist["owner"]["id"] != fromID:
requests.put("https://api.spotify.com/v1/playlists/{0}/followers".format(playlist["id"]), headers=toHeader)
print("Playlist {0} is now being followed".format(playlist["name"]))
#Import privates
else:
#Create new playlist
playlistData = {
"name": playlist["name"],
"public": playlist["public"],
"description": playlist["description"] }
newPlaylist = requests.post("https://api.spotify.com/v1/users/{0}/playlists".format(toID), headers=toHeader, json=playlistData)
print("Created new playlist with name {0}".format(playlist["name"]))
#Get songs
songs = []
data = {
"market": "from_token",
"fields": "items(track(uri)),total",
"limit": 100,
"offset": 0
}
while True:
r = requests.get(playlist["tracks"]["href"], headers=fromHeader, params=data)
for song in r.json()["items"]:
songs.append(song["track"]["uri"])
if len(songs) == r.json()["total"]: break
else: data["offset"] += data["limit"]
print("Found {0} songs".format(len(songs)))
#Import songs
for i in range(0, len(songs), 100):
requests.post("https://api.spotify.com/v1/playlists/{0}/tracks".format(newPlaylist.json()["id"]), headers=toHeader, json={"uris": songs[i:min(i+100, len(songs))]})
print("Imported {0} songs".format(len(songs)))
def TransferTracks(fromHeader, fromID, toHeader, toID):
print("Importing tracks...")
#Get from old
tracks = []
data = {
"market": "from_token",
"limit": 50,
"offset": 0 }
while True:
r = requests.get("https://api.spotify.com/v1/me/tracks", headers=fromHeader, params=data)
for i in r.json()["items"]:
tracks.append(i["track"]["id"])
if r.json()["total"] == len(tracks): break
else: data["offset"] += data["limit"]
print("Found {0} saved tracks".format(len(tracks)))
#Import to new
for i in range(0 , len(tracks), 50):
requests.put("https://api.spotify.com/v1/me/tracks", headers=toHeader, json={"ids": tracks[i:min(i+50, len(tracks))]})
print("Imported {0} tracks".format(len(tracks)))
def TransferAlbums(fromHeader, fromID, toHeader, toID):
print("Importing albums...")
#Get from old
albums = []
data = {
"market": "from_token",
"limit": 50,
"offset": 0 }
while True:
r = requests.get("https://api.spotify.com/v1/me/albums", headers=fromHeader, params=data)
for i in r.json()["items"]:
albums.append(i["album"]["id"])
if r.json()["total"] == len(albums): break
else: data["offset"] += data["limit"]
print("Found {0} saved albums".format(len(albums)))
#Import to new
for i in range(0 , len(albums), 50):
requests.put("https://api.spotify.com/v1/me/albums", headers=toHeader, json={"ids": albums[i:min(i+50, len(albums))]})
print("Imported {0} albums".format(len(albums)))
def TransferShows(fromHeader, fromID, toHeader, toID):
print("Importing shows...")
#Get from old
shows = []
data = {
"market": "from_token",
"limit": 50,
"offset": 0 }
while True:
r = requests.get("https://api.spotify.com/v1/me/shows", headers=fromHeader, params=data)
for i in r.json()["items"]:
shows.append(i["show"]["id"])
if r.json()["total"] == len(shows): break
else: data["offset"] += data["limit"]
print("Found {0} saved shows".format(len(shows)))
#Import to new
for i in range(0 , len(shows), 50):
requests.put("https://api.spotify.com/v1/me/shows", headers=toHeader, json={"ids": shows[i:min(i+50, len(shows))]})
print("Imported {0} shows".format(len(shows)))
def TransferArtists(fromHeader, fromID, toHeader, toID):
print("Importing artists...")
#Get from old
artists = []
data = {
"type": "artist",
"limit": 50
}
while True:
r = requests.get("https://api.spotify.com/v1/me/following", headers=fromHeader, params=data)
for i in r.json()["artists"]["items"]:
artists.append(i["id"])
if r.json()["artists"]["total"] == len(artists): break
else: data["after"] = r.json()["artists"]["cursor"]["after"]
print("Found {0} followed artists".format(len(artists)))
#Import to new
for i in range(0, len(artists), 50):
requests.put("https://api.spotify.com/v1/me/following", headers=toHeader, params={"type": "artist"}, json={"ids": artists[i:min(i+50, len(artists))]})
print("Imported {0} artists".format(len(artists)))
# Variables
##oldCredentials = { "login": "[email protected]", "pass": "M@t3J12e2Ee"}
##newCredentials = { "login": "[email protected]", "pass": "M@t3J12e2Ee" }
cc = { "number": "", "exp_date": "", "cvv": ""}
oldCredentials = { "login": "", "pass": ""}
newCredentials = { "login": "", "pass": "" }
# User input
InputSetup(oldCredentials, newCredentials, cc)
# Create / Login to new account
newSpotify_session = webdriver.Chrome("chromedriver.exe")
if newCredentials["login"]:
LoginSession(newSpotify_session, newCredentials["login"], newCredentials["pass"])
else:
newCredentials = GenerateAccount(newSpotify_session)
# Login to old, authorize and transfer to new
if oldCredentials["login"]:
oldSpotify_session = webdriver.Chrome("chromedriver.exe")
LoginSession(oldSpotify_session, oldCredentials["login"], oldCredentials["pass"])
fromAuthCode = Authorize(oldSpotify_session)
toAuthCode = Authorize(newSpotify_session)
Transfer(fromAuthCode, toAuthCode)
# Activate subscription
if cc["number"]:
ActivateTrial(newSpotify_session, cc)
print("Done!\n")
input("Press Enter to exit...")