Skip to content

Instantly share code, notes, and snippets.

@kamui-fin
Created October 28, 2020 23:28
Show Gist options
  • Save kamui-fin/dd364a0e23587a834d1a63e6dcc2de29 to your computer and use it in GitHub Desktop.
Save kamui-fin/dd364a0e23587a834d1a63e6dcc2de29 to your computer and use it in GitHub Desktop.
import pathlib
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
LINKS_PATH = "links.txt"
beatmap_file = pathlib.Path(LINKS_PATH)
beatmaps = [x.strip() for x in beatmap_file.read_text("utf-8").split("\n")]
num_beatmaps = len(beatmaps)
driver = webdriver.Firefox()
driver.get("https://osu.ppy.sh/home")
ready = input("Login to your account and press enter once you're done: ")
for beat_num, beatmap in enumerate(beatmaps):
print(f"Downloading beatmap {beat_num + 1} of {num_beatmaps}")
if "https://osu.ppy.sh/beatmapsets" in beatmap:
driver.get(beatmap)
download_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn-osu-big:nth-child(2)")))
if "Video" in download_button.text:
download_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn-osu-big:nth-child(3)")))
download_button.click()
else:
with open("bloodcats.txt", encoding="utf-8", mode="a") as f:
f.write(beatmap + "\n")
print("Done!")
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment