Почему бот Spotify не работает?Python

Программы на Python
Гость
Почему бот Spotify не работает?

Сообщение Гость »

Я разработал бота Spotify.
Здесь я не могу решить проблему синхронизации между моей учетной записью и новой учетной записью, созданной этим ботом.
Если я установлю время воспроизведения как 31 с., мой аккаунт играет 31 с, но иногда играет меньше или больше времени.
Я не могу решить эту проблему.
from selenium import webdriver
from datetime import datetime
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select
from pynput.keyboard import Key, Controller
from twocaptcha import TwoCaptcha

Artist = 'https://open.spotify.com/intl-es/artist ... 0eb9f041f0' # the link you want to follow
dirver_address = r"C:/Users/autom/.wdm/drivers/chromedriver/win64/121.0.6167.85/chromedriver-win32/chromedriver.exe"
follow = True # follow option, True: follow activated, False: inactivated.
like = True # like option, True: activate, False: inactivate
playtime = 33 #playing time

keyboard = Controller()
# Function to read lines from a file and return them as an array
def leer_lineas_a_array(filename):
with open(filename, 'r') as file:
# Read all lines from the file and store them in an array
# List comprehension skips empty lines
lines = [line.strip() for line in file if line.strip()]
return lines

def solve_captcha(login_url):
print('Solving the captcha')
api_key = '52db636ac53060f310c49dd6ea941ef6'
solver = TwoCaptcha(api_key)
site_key = "6LeO36obAAAAALSBZrY6RYM1hcAY7RLvpDDcJLy3"
code = solver.solve_captcha(site_key = site_key, page_url = login_url)
print(f"Successfully solved the captcha. Captcha token: {code}")
return code

def submit_captcha(driver, code):
script = '''
function retrieveCallback(obj, visited = new Set()) {
if (typeof obj === 'function') return obj;
for (const key in obj) {
if (!visited.has(obj[key])) {
visited.add(obj[key]);
if (typeof obj[key] === 'object' || typeof obj[key] === 'function') {
const value = retrieveCallback(obj[key], visited);
if (value) {
return value;
}
}
visited.delete(obj[key]);
}
}
}
const callback = retrieveCallback(window.___grecaptcha_cfg.clients[0]);
if (typeof callback === 'function') {
callback('%s');
} else {
throw new Error('Callback function not found.');
}
''' % code
driver.execute_script(script)

def main():
# VARIABLES
# URL of the artist page on Spotify
urlArtist = Artist
# Seconds to wait to play next song
timePlay = playtime

gmail = "janharris" + datetime.now().strftime('%Y%m%d%H%M%S') + "@gmail.com"
password = "Sportify@123"
displayName = "Pedro"
year = "1993"
month = datetime.now().strftime('%m')
day = datetime.now().strftime('%d')
options = webdriver.ChromeOptions()
ser = webdriver.ChromeService(executable_path=dirver_address)
driver = webdriver.Chrome(service=ser)
driver.get("https://spotify.com/")
time.sleep(3)
try:
cookie_btn = driver.find_element(By.ID, 'onetrust-accept-btn-handler')
cookie_btn.click()
print("click cookie button")
except:
print("not found cookie button")
time.sleep(1)
signup_btn = driver.find_element(By.XPATH, '//*[@data-testid="signup-button"]')
signup_btn.click()
time.sleep(3)
username_input = driver.find_element(By.ID, 'username')
username_input.send_keys(gmail)
time.sleep(1)
submit_btn = driver.find_element(By.XPATH, '//*[@data-testid="submit"]')
submit_btn.click()
time.sleep(2)
password_input = driver.find_element(By.ID, 'new-password')
password_input.send_keys(password)
time.sleep(1)
submit_btn = driver.find_element(By.XPATH, '//*[@data-testid="submit"]')
submit_btn.click()
time.sleep(2)
displayName_input = driver.find_element(By.ID, 'displayName')
displayName_input.send_keys(displayName)
month_select = Select(driver.find_element(By.ID, 'month'))
month_select.select_by_value('1')
day_input = driver.find_element(By.ID, 'day')
day_input.send_keys(day)
year_input = driver.find_element(By.ID, 'year')
year_input.send_keys(year)
gender_option_radio = driver.find_element(By.XPATH, '//div[@data-encore-id="formRadio"]')
gender_option_radio.click()
submit_btn = driver.find_element(By.XPATH, '//*[@data-testid="submit"]')
submit_btn.click()
time.sleep(2)
submit_btn = driver.find_element(By.XPATH, '//*[@data-testid="submit"]')
submit_btn.click()
time.sleep(4)

# Solve recaptcha
login_url = driver.current_url
print(login_url)
code = solve_captcha(login_url)
submit_captcha(driver, code)

continue_btn = driver.find_element(By.XPATH, '//button[@data-encore-id="buttonPrimary"]')
continue_btn.click()
time.sleep(3)

driver.get(urlArtist)
time.sleep(5)
# Wait for the "Follow" button to be present and then click it if it says "Follow"
if follow:
boton_seguir = driver.find_element(By.XPATH, '//*[@data-encore-id="buttonSecondary"]')
print(boton_seguir.text)
if boton_seguir.text == 'Seguir' or boton_seguir.text == 'Follow':
boton_seguir.click()
print("click follow_button")
else:
print("found follow_button")

while True:

# Loop to open each playlist URL from the file and play it
for urlPlaylist in leer_lineas_a_array('links.txt'):
print(urlPlaylist)
start_time = datetime.now()
driver.get(urlPlaylist)
time.sleep(2)

try:
boton_reproducir = driver.find_element(By.XPATH, '//div[@data-testid="action-bar-row"]/div/button[@data-testid="play-button"]')
boton_reproducir.click()
print("click play_pause_button")
except:
print("not found play_button")

if like:
try:
boton_like = driver.find_element(By.XPATH, '//div[@data-testid="action-bar-row"]/button[@data-testid="add-button"]')
if boton_like.get_attribute("aria-checked") == "false":
boton_like.click()
print("click add_to_button")
else:
print("found add_to_button")
except:
print("not found add_to_button")
try:
boton_login = driver.find_element(By.XPATH, '//div[@data-testid="dialog-root"]/div[@class="miG_SXrw265mkozdEHrJ"]/p[@class="CMgJZD0JMx_Yz1tlE7hd"]/a')
boton_login.click()
print('login button clicked')
try:
login_username_input = driver.find_element(By.ID, 'login-username')
login_username_input.clear()
time.sleep(2)
login_username_input.send_keys(gmail)
login_password_input = driver.find_element(By.ID, 'login-password')
login_password_input.clear()
time.sleep(2)
login_password_input.send_keys(password)
login_button = driver.find_element(By.ID, 'login-button')
login_button.click()
print('find elements')
try:
# time.sleep(1500)
recaptcha_login = driver.find_element(By.XPATH, '//div[@class="rc-anchor rc-anchor-normal rc-anchor-dark"]')
time.sleep(2)
print('find repatcha_login element')
recaptcha_login.click()
continue_btn = driver.find_element(By.XPATH, '//button[@data-encore-id="buttonPrimary"]')
continue_btn.click()
time.sleep(3)
except:
print('not found recapture')
except:
print('cannot find elements')
except:
print('can not find login button')

time.sleep(timePlay)

if __name__ == '__main__':
main()


Подробнее здесь: https://stackoverflow.com/questions/781 ... fy-bot-run

Вернуться в «Python»