Untitled
unknown
plain_text
a year ago
3.0 kB
2
Indexable
Never
import spotipy from client_info import ClientInfo from spotipy.oauth2 import SpotifyClientCredentials from selenium import webdriver import time import random from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Where client info is stored client_info = ClientInfo() playlist_id = "1ic62kllAxB9L3zGq1x9b5" # Playlist from Au/Ra - All of Au/Ra # Client log in sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials( client_id=client_info.client_id, client_secret=client_info.client_secret, )) def get_playlist_track_ids(playlist_id): ids = [] # Getting items from playlist tracks = sp.playlist_items(playlist_id=playlist_id) # Extracting track IDs, names, and popularity for track in tracks["items"]: ids.append(track["track"]["id"]) # Getting audio features of each track return ids # track_ids = get_playlist_track_ids(playlist_id) track_ids = ['2EHJ5ZAQoIzdZLstK1mi80', '5IuxzbYmjIr5jdVYpSuqNz', '6CWhliSvjMd1C6NoseLbbK', '6R8dWaieowceosgrrcHBAL', '4b36UcIJuixrPDoBXg4Pc5', '3sgs99TbrcK2dodseaCK5M', '1gmTOtHT21T7glc2uwJfow', '4mB0hmUiwO1ND3R741rGU0', '4LzdRADthVKiK2nnwFnn7h', '6QkjBOwIRoRPDOQNULWgiC', '7CH8J4ulT49UfZwSDSkSZA', '0pxEmbA0ivhMStnDj9ANv3', '5TgS4dcUAU8EEb506d8wAT', '3i5jKbMOcBqgnKlx5UyH9d', '1VYruNWR6k3fKQL5LXtIIK', '7uUahoeqGNRMbpdeiLj1rS', '4n2bLMX5M9XKtU2w7vzhhp', '7tuV9cleysQqDPQ66Z5FpR', '4sR6DaImxZ6XNgRXgTTOQ3', '1fgC2MHbJnPgvDfdTpC62c', '5LtEwkDUhKB2GktVX9A2QH', '3AJgha8H2NyI7rVt0JRa5A', '7bZL8w4bwW1a7KFte4Fntv', '6Z1nIeD7mfejUFf6rKq2AY', '3JODhv0i37KChbC4OPEoAd', '7mEMM7BxfvsuStN30l3Fgc', '7qtX448rtlP2tJf1HfSJ6K', '16HjgTdwcUdxV5ubUMCd7x', '1snWlbcbgQpJfknoI30DWG', '6RGkwhDLaHxWWXY0jn1jFv', '1wqCx4RZ8yABTkbh3Dx33W', '2POTiIlEieiR3vUmgswxfl', '4VyvzQoIfG49xiNuYVYBiv', '36LcavooRmf39fYgsCykUs', '1PHF7mIPfVGqToeDHZQjqn', '3MkuFR7t25mu7Iscp6GGiV', '5NmiSGDDlwh8oUMEOd8PSp', '3JGWeOFpnoxwNSSbaUCiOi', '6mCucrcLeSkhhBeTdZyuaB', '6tYdxEQSnC0rh9W2OaK5oV', '01QoNqGqD5vd5vt3e2gRHV'] # -------------------------- Webscraping -------------------------- # three_dots = "buttonTertiary" credits_button = "wC9sIed7pfp47wZbmU6m NmbeQabkSLXf0mTAhSLl" def random_proxy(): with open("valid_proxies.txt", mode='r') as file: proxies = file.readlines() return str(random.choice(proxies)) proxy = random_proxy() print(proxy) URL = f"https://open.spotify.com/track/{track_ids[0]}" options = webdriver.ChromeOptions() # options.add_argument(f'--proxy-server={proxy}') options.add_argument("--incognito") driver = webdriver.Chrome(options=options) driver.get(URL) time.sleep(3) try: # BY ID? element1 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, three_dots))) element1.click() print("Clicked") except: print("Didn't work") time.sleep(100) driver.quit()