forked from useragents/Proxyless-Spotify-Follow-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow_bot.py
114 lines (106 loc) · 5.06 KB
/
follow_bot.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
import requests
import random
import string
class spotify:
def __init__(self, profile, proxy=None):
self.session = requests.Session()
self.profile = profile
self.proxy = proxy
def register_account(self):
headers = {
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://www.spotify.com/"
}
email = ("").join(random.choices(string.ascii_letters + string.digits, k = 8)) + "@gmail.com"
password = ("").join(random.choices(string.ascii_letters + string.digits, k = 8))
proxies = None
if self.proxy is not None:
proxies = {"https": f"http://{self.proxy}"}
data = f"birth_day=1&birth_month=01&birth_year=1970&collect_personal_info=undefined&creation_flow=&creation_point=https://www.spotify.com/uk/&displayname=CoolName&email={email}&gender=neutral&iagree=1&key=a1e486e2729f46d6bb368d6b2bcda326&password={password}&password_repeat={password}&platform=www&referrer=&send-email=1&thirdpartyemail=0&fb=0"
try:
create = self.session.post("https://spclient.wg.spotify.com/signup/public/v1/account", headers = headers, data = data, proxies = proxies)
if "login_token" in create.text:
login_token = create.json()['login_token']
with open("Created.txt", "a") as f:
f.write(f'{email}:{password}:{login_token}\n')
return login_token
else:
return None
except:
return False
def get_csrf_token(self):
try:
r = self.session.get("https://www.spotify.com/uk/signup/?forward_url=https://accounts.spotify.com/en/status&sp_t_counter=1")
return r.text.split('csrfToken":"')[1].split('"')[0]
except:
return None
def get_token(self, login_token):
headers = {
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"X-CSRF-Token": self.get_csrf_token(),
"Host": "www.spotify.com"
}
self.session.post("https://www.spotify.com/api/signup/authenticate", headers = headers, data = "splot=" + login_token)
headers = {
"accept": "application/json",
"Accept-Encoding": "gzip, deflate, br",
"accept-language": "en",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
"spotify-app-version": "1.1.52.204.ge43bc405",
"app-platform": "WebPlayer",
"Host": "open.spotify.com",
"Referer": "https://open.spotify.com/"
}
try:
r = self.session.get(
"https://open.spotify.com/get_access_token?reason=transport&productType=web_player",
headers = headers
)
return r.json()["accessToken"]
except:
return None
def follow(self):
if "/user/" in self.profile:
self.profile = self.profile.split("/user/")[1]
self.profile = self.profile.split("?")[0]
mode = 0
elif "/playlist/" in self.profile:
self.profile = self.profile.split("/playlist/")[1]
self.profile = self.profile.split("?")[0]
mode = 1
login_token = self.register_account()
if login_token == None:
return None, "Ratelimit"
elif login_token is False:
if self.proxy is None:
return None, f"unable to send request on register"
return None, f"Bad proxy {self.proxy}"
auth_token = self.get_token(login_token)
if auth_token is None:
return None, "While getting auth token"
headers = {
"accept": "application/json",
"Accept-Encoding": "gzip, deflate, br",
"accept-language": "en",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
"app-platform": "WebPlayer",
"Referer": "https://open.spotify.com/",
"spotify-app-version": "1.1.52.204.ge43bc405",
"authorization": "Bearer {}".format(auth_token),
}
if mode == 0:
self.session.put(
"https://api.spotify.com/v1/me/following?type=user&ids=" + self.profile,
headers = headers
)
return True, None
else:
self.session.put(
"https://api.spotify.com/v1/playlists/" + self.profile + "/followers",
headers = headers
)
return True, None