Spaces:
Runtime error
Runtime error
File size: 5,036 Bytes
20a50c3 7f45966 20a50c3 7f45966 20a50c3 7f45966 20a50c3 7f45966 | 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 | from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.chrome.options import Options
import os
from pyspark.sql import SparkSession
from delta import configure_spark_with_delta_pip
import tempfile
def get_mp3(song_title):
# Set the download directory to the "music" subfolder within the current directory
download_directory = os.path.join(os.getcwd(), "music")
os.makedirs(download_directory, exist_ok=True)
# Set up Chrome options
chrome_options = Options()
chrome_options.add_experimental_option("prefs", {
"download.default_directory": download_directory,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
# Set up the Selenium WebDriver (e.g., Chrome)
driver = webdriver.Chrome(options=chrome_options)
# Navigate to the website
driver.get("https://suno.com/me")
# Wait for the sign-in button to be clickable and click it
sign_in_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#__next > div > div > div > div > div.cl-main.🔒️.cl-internal-xk295g > div > button.cl-socialButtonsIconButton.cl-socialButtonsIconButton__discord.🔒️.cl-internal-855i1h"))
)
sign_in_button.click()
# Wait for the username field to be visible and enter the username
#username: applebottom_12
username_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#uid_8"))
)
username_field.send_keys("asfasfasfgasdfasgfsag@gmail.com")
# Find the password field and enter the password
password_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#uid_10"))
)
password_field.send_keys("AppleBottom12")
# Find the password button and click it
password_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#app-mount > div.appAsidePanelWrapper__5e6e2 > div.notAppAsidePanel__95814 > div.app_b1f720 > div > div > div > div > form > div.centeringWrapper__5e247 > div > div.mainLoginContainer_f58870 > div.block__681fa.marginTop20__7e0ad > button.marginBottom8_ce1fb9.button__5573c.button__581d0.lookFilled__950dd.colorBrand__27d57.sizeLarge_b395a7.fullWidth_fdb23d.grow__4c8a4"))
)
password_button.click()
# Wait for the page to load after signing in
WebDriverWait(driver, 10).until(
EC.url_contains("https://suno.com/me")
)
# Click on the specific song
three_dots = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.LINK_TEXT, song_title))
)
three_dots.click()
# Play the song
play_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "body > div.css-fhtuey > div.css-bhm5u7 > div > div.css-l9hfgy > div.css-144pizt > button.chakra-button.css-15rci1t"))
)
play_button.click()
time.sleep(3)
three_dots = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[@aria-label="More Actions"]'))
)
three_dots.click()
# Wait for the Download button to be clickable and click on it
download_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//div[@role="menuitem" and contains(text(), "Download")]'))
)
download_button.click()
# Wait for the Audio element to be clickable and click on it
audio_element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//div[@role="menuitem" and contains(text(), "Audio")]'))
)
audio_element.click()
time.sleep(3)
# print("Successfully signed in!")
# # Create a SparkSession with Delta Lake configuration
# builder = SparkSession.builder.appName("SaveMP3ToDatabricks") \
# .config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension") \
# .config("spark.sql.catalog.spark_catalog", "org.apache.spark.sql.delta.catalog.DeltaCatalog")
# spark = configure_spark_with_delta_pip(builder).getOrCreate()
# # Setting the Retrieving Director
# retrieve_directory = os.path.join(download_directory, f"{song_title}.mp3")
# # Read the downloaded MP3 file as binary
# mp3_data = spark.sparkContext.binaryFiles(retrieve_directory).collect()[0][1]
# # Create a DataFrame with the MP3 data
# df = spark.createDataFrame([("Samba Kickoff.mp3", mp3_data,)], ["song_name", "mp3_data"])
# # Save the DataFrame to a Databricks table
# df.write.format("delta").mode("append").saveAsTable("mp3_table")
# print("MP3 file saved to Databricks table.")
driver.quit() |