-
Notifications
You must be signed in to change notification settings - Fork 8
/
stream_new2.py
428 lines (371 loc) · 17.4 KB
/
stream_new2.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
import selenium.webdriver as uc
from undetected_chromedriver import ChromeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time
import random
import math
from datetime import datetime, date
import os
import re
import csv
from resources.agents_sizes import user_agents_desktop, window_sizes_desktop, user_agents_mobile, window_sizes_mobile, \
window_desk_test
from resources.pathes import CHROME_PROFILES, DRIVER_PATH, USER_FOLDER, USER_LIST_TXT_PATH, CHROME_PROFILES_REGISTER
from resources.add_ons import TODAY_DATE, NOW_TIME
from resources.links import LINKS_TO_PLAY
from user_input import TASK_FIRST, NUMBER_SKIP, MAX_PLAY_TIME, MIN_PLAY_TIME, FOLLOW_SAVE_VAR
import resources.pathes as p
import user_input
class SpotifyBot:
def __init__(self, username, password):
self.username = username
self.password = password
options = Options()
options.add_argument(f"--window-size={random.choice(window_sizes_desktop)}")
options.add_argument(f'--user-agent={random.choice(user_agents_desktop)}')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument("--disable-extensions")
options.add_argument("--proxy-server='direct://'")
options.add_argument("--proxy-bypass-list=*")
options.add_argument('--ignore-certificate-errors')
options.add_argument("--password-store=basic")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-extensions")
options.add_argument("--enable-automation")
options.add_argument("--disable-browser-side-navigation")
options.add_argument("--disable-web-security")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-infobars")
options.add_argument("--disable-gpu")
options.add_argument("--disable-setuid-sandbox")
options.add_argument("--disable-software-rasterizer")
options.add_argument(f"--user-data-dir={CHROME_PROFILES}{username}")
# options.add_argument('--proxy-server=85.195.81.151:12971')
# options.add_argument(f'--proxy-server=https://85.195.81.151:12971')
# options.add_argument("--incognito")
# options.add_argument('--headless')
# options.headless = True
s = Service(
executable_path=DRIVER_PATH)
self.browser = uc.Chrome(service=s, options=options)
self.wait = WebDriverWait(self.browser, user_input.WEBSITE_LOAD_TIME)
self.wait_follow = WebDriverWait(self.browser, 3)
def test_wait(self):
browser = self.browser
wait = self.wait
browser.get('https://open.spotify.com/artist/6LuN9FCkKOj5PcnpouEgny')
time.sleep(1)
browser.get('https://google.com')
wait.until(EC.visibility_of_element_located((By.XPATH, p.PLAY_ARTIST_XPATH1))).click()
# print('wait function didnt work')
time.sleep(1000)
def close_browser(self):
self.browser.close()
self.browser.quit()
def login(self, user_line):
browser = self.browser
browser.get('https://open.spotify.com/')
time.sleep(random.randrange(3, 5))
xpath1 = '//*[@id="main"]/div/div[2]/div[1]/header/div[5]/button[2]/span'
xpath2 = '/html/body/div[3]/div/div[2]/div[1]/header/div[5]/button[2]/span'
if self.xpath_exists(xpath1 or xpath2):
print('[-] Not Logged in, trying to login')
browser.get('https://accounts.spotify.com/login')
time.sleep(random.randrange(5, 7))
self.get_cookie_at_login()
username_input = browser.find_element(by=By.ID, value='login-username')
username_input.clear()
username_input.send_keys(username)
time.sleep(random.randrange(1, 2))
password_input = browser.find_element(by=By.ID, value='login-password')
password_input.clear()
password_input.send_keys(password)
time.sleep(random.randrange(1, 3))
password_input.send_keys(Keys.ENTER)
time.sleep(random.randrange(11, 14))
browser.get('https://open.spotify.com/')
time.sleep(3)
self.get_cookie_at_login()
if self.xpath_exists(xpath1 or xpath2):
print(f'[-] NOT LOGGED IN!')
user_to_delete_list.append(user_line)
with open('./resources/DATADELETE.txt', mode='a') as fps:
a = ''.join(user_line)
fps.write(str(a + '\n'))
print(a)
fps.close()
self.close_browser()
else:
print(f'[+] Logged in!')
else:
print('[+] Logged in!')
def get_cookie_at_login(self):
browser = self.browser
try:
browser.find_element(By.ID, 'onetrust-accept-btn-handler').click()
time.sleep(random.randrange(1, 2))
except:
pass
# look if element on page with XPATH
def xpath_exists(self, url):
browser = self.browser
try:
browser.find_element(by=By.XPATH, value=url)
exist = True
except NoSuchElementException:
exist = False
return exist
def partial_link_text(self, url):
browser = self.browser
try:
browser.find_element(by=By.PARTIAL_LINK_TEXT, value=url)
exist = True
except NoSuchElementException:
exist = False
return exist
def skip_forward(self, play_time):
browser = self.browser
xpath1 = '//*[@id="main"]/div/div[2]/div[2]/footer/div/div[2]/div/div[1]/div[2]/button[1]'
xpath2 = '/html/body/div[4]/div/div[2]/div[2]/footer/div/div[2]/div/div[1]/div[2]/button[1]'
if self.xpath_exists(xpath1):
self.wait.until(EC.visibility_of_element_located((By.XPATH, xpath1))).click()
time.sleep(play_time)
if self.xpath_exists(xpath2):
self.wait.until(EC.visibility_of_element_located((By.XPATH, xpath2))).click()
time.sleep(play_time)
else:
print('[-] could not skip')
def skip_back(self, play_time):
browser = self.browser
xpath1 = '//*[@id="main"]/div/div[2]/div[2]/footer/div/div[2]/div/div[1]/div[1]/button[2]'
xpath2 = '/html/body/div[4]/div/div[2]/div[2]/footer/div/div[2]/div/div[1]/div[1]/button[2]'
if self.xpath_exists(xpath1):
browser.find_element(by=By.XPATH, value=xpath1).click()
time.sleep(play_time)
if self.xpath_exists(xpath2):
browser.find_element(by=By.XPATH, value=xpath1).click()
time.sleep(play_time)
else:
print('[-] could not skip')
def play(self, play_time, skip_number):
browser = self.browser
for link in LINKS_TO_PLAY:
try:
browser.get(link)
# time.sleep(random.randrange(8, 12))
a = (''.join(link))
a = re.split('/', a)[3]
print(f'processing {a}: {link}')
self.get_cookie_at_login()
if a == 'artist':
self.wait.until(EC.visibility_of_element_located((By.XPATH, p.PLAY_ARTIST_XPATH1))).click()
time.sleep(random.randrange(1, 2))
self.get_cookie_at_login()
# follow/save
if FOLLOW_SAVE_VAR is True:
try:
browser.find_element(By.XPATH, p.FOLLOW_ARTIST_XPATH1).click()
except:
print('[-] could not follow/save!!!')
if skip_number > 0:
for number in range(skip_number):
self.skip_forward(play_time)
print(f'[+] played {number} songs, each {play_time}')
elif skip_number <= 0:
time.sleep(play_time)
print(f'[+] played: {play_time} sec')
else:
print(f'[-] WRONG XPATH! {username}')
if a == 'playlist':
self.wait.until(EC.visibility_of_element_located((By.XPATH, p.PLAY_PLAYLIST_XPATH1))).click()
time.sleep(random.randrange(1, 2))
self.get_cookie_at_login()
if FOLLOW_SAVE_VAR is True:
try:
browser.find_element(By.XPATH, p.SAVE_PLAYLIST_XPATH1).click()
except:
print('[-] could not follow/save!!!')
# skip method
if skip_number > 0:
for number in range(skip_number):
self.skip_forward(play_time)
print(f'[+] played {number} songs, each {play_time}')
elif skip_number <= 0:
time.sleep(play_time)
print(f'[+] played: {play_time} sec')
else:
print(f'[-] WRONG XPATH! {username}')
if a == 'track':
self.wait.until(EC.visibility_of_element_located((By.XPATH, p.PLAY_SONG_XPATH1))).click()
time.sleep(random.randrange(1, 2))
self.get_cookie_at_login()
if FOLLOW_SAVE_VAR is True:
try:
browser.find_element(By.XPATH, p.SAVE_PLAYLIST_XPATH1).click()
except:
print('[-] could not follow/save!!!')
# skip method
if skip_number > 0:
for number in range(skip_number):
self.skip_forward(play_time)
print(f'[+] played {number} songs, each {play_time}')
elif skip_number <= 0:
time.sleep(play_time)
print(f'[+] played: {play_time} sec')
else:
print(f'[-] WRONG XPATH! {username}')
if a == 'album':
self.wait.until(EC.visibility_of_element_located((By.XPATH, p.PLAY_ALBUM_XPATH1))).click()
time.sleep(random.randrange(1, 2))
self.get_cookie_at_login()
if FOLLOW_SAVE_VAR is True:
try:
browser.find_element(By.XPATH, p.SAVE_ALBUM_XPATH1).click()
except:
print('[-] could not follow/save!!!')
# skip method
if skip_number > 0:
for number in range(skip_number):
self.skip_forward(play_time)
print(f'[+] played {number} songs, each {play_time}')
elif skip_number <= 0:
time.sleep(play_time)
print(f'[+] played: {play_time} sec')
else:
print(f'[-] WRONG XPATH! {username}')
if a == 'user':
if FOLLOW_SAVE_VAR is True:
self.get_cookie_at_login()
self.wait.until(EC.visibility_of_element_located((By.XPATH, p.FOLLOW_USER_XPATH1))).click()
time.sleep(random.randrange(1, 2))
else:
print(f'[-] could not follow!!! {username}')
except Exception as ex2:
print(ex2)
print('\033[91m' + '[-] process interrupted' + '\033[0m')
continue
def test_profile(self):
browser = self.browser
browser.get('https://myip.com')
time.sleep(10)
browser.get('https://nowsecure.nl')
time.sleep(10)
browser.get('https://distilnetworks.com')
time.sleep(10)
browser.get('https://myuseragent.com')
time.sleep(1000)
user_to_delete_list = []
if __name__ == '__main__':
start = time.time()
taskFirst = TASK_FIRST
if taskFirst == 0:
user_count = 0
with open('./resources/dataOG.txt', mode='r+') as fp:
reader = csv.reader(fp, delimiter=',')
line = 0
for row in reader:
line += 1
# where to start in the user list >
if user_input.STREAM1_MAX_USER_NUM + 1 > line > user_input.STREAM_START_NUM:
try:
b = ''.join(row)
# print(b)
username = re.split(':', b)[0]
print(f'[+] User: ' + username)
password = re.split(':', b)[1]
# time.sleep(0.5)
my_bot = SpotifyBot(username, password)
my_bot.login(b)
# delete_user()
# my_bot.testik()
# song_play_time = random.randrange(MIN_PLAY_TIME, MAX_PLAY_TIME)
#
# my_bot = SpotifyBot(username, password)
# my_bot.login()
# # my_bot.play(song_play_time, NUMBER_SKIP)
time.sleep(random.randrange(1, 2))
my_bot.close_browser()
time.sleep(random.randrange(1, 2))
user_count += 1
print('\033[93m' + f'[...] {user_count} user(s) finished' + '\033[0m' + '\n')
except Exception as ex:
print(ex)
print('\n' + '\033[94m' + '\033[1m' + f''' -- USER COUNT: {user_count} --''' + '\033[0m' + '\n' + '\n')
# direct play
if taskFirst == 1:
user_count = 0
with open(USER_LIST_TXT_PATH, mode='r') as fp:
reader = csv.reader(fp, delimiter=',')
line = 0
for row in reader:
line += 1
# where to start in the user list >
if user_input.STREAM1_MAX_USER_NUM + 1 > line > user_input.STREAM_START_NUM:
try:
b = ''.join(row)
# print(b)
username = re.split(':', b)[0]
print(f'[+] User: ' + username)
password = re.split(':', b)[1]
# print(password)
song_play_time = random.randrange(MIN_PLAY_TIME, MAX_PLAY_TIME)
my_bot = SpotifyBot(username, password)
# my_bot.login()
my_bot.play(song_play_time, NUMBER_SKIP)
time.sleep(random.randrange(1, 2))
my_bot.close_browser()
time.sleep(random.randrange(1, 2))
user_count += 1
print('\033[93m' + f'[...] {user_count} user(s) finished' + '\033[0m' + '\n')
except Exception as ex:
print(ex)
raise
print('\n' + '\033[94m' + '\033[1m' + f''' -- USER COUNT: {user_count} --''' + '\033[0m' + '\n' + '\n')
# with login
if taskFirst == 2:
time.sleep(user_input.USER_START_SLEEP)
user_count = 0
with open(USER_LIST_TXT_PATH, mode='r') as fp:
reader = csv.reader(fp, delimiter=',')
line = 0
for row in reader:
line += 1
# where to start in the user list >
if user_input.STREAM2_MAX_USER_NUM + 1 > line > user_input.STREAM1_MAX_USER_NUM:
try:
b = ''.join(row)
# print(b)
username = re.split(':', b)[0]
print(f'[+] User: ' + username)
password = re.split(':', b)[1]
# print(password)
song_play_time = random.randrange(MIN_PLAY_TIME, MAX_PLAY_TIME)
my_bot = SpotifyBot(username, password)
my_bot.login(b)
my_bot.play(song_play_time, NUMBER_SKIP)
time.sleep(random.randrange(1, 2))
my_bot.close_browser()
time.sleep(random.randrange(1, 2))
user_count += 1
print('\033[93m' + f'[...] {user_count} user(s) finished' + '\033[0m' + '\n')
except Exception as ex:
print(ex)
continue
continue
print('\n' + '\033[94m' + '\033[1m' + f''' -- USER COUNT: {user_count} --''' + '\033[0m' + '\n' + '\n')
USER_COUNT_SN_2 = user_count
else:
print(f'Wrong number! Try again!')
end = time.time()
time_used = end - start
time_used_sec = int(math.ceil(time_used))
print(f'Time used {time_used_sec} second(s)')
time_used_minutes = time_used_sec / 60
print(f'Time used {round(time_used_minutes)} minute(s)')