Amazing-Python-Scripts
82 строки · 2.5 Кб
1import time2import os3import sys4from pathlib import Path5from plyer import notification as nt6from selenium import webdriver7from selenium.webdriver.common.keys import Keys8
9path_to_downloads = os.path.join(Path.home(), "Downloads")10
11songs_list_path = os.path.join(12Path.home(), "Desktop", "Songs List for Automated Download.txt")13
14if not os.path.exists(songs_list_path):15f_temp = open(songs_list_path, 'w')16f_temp.close()17nt.notify(18title="Mp3 Songs Automatic Downloader",19message='A temporary file named "Songs List for Automated Download" has been created. Please enter the songs (one in each line), save it and run the application again!',20timeout=1521)22sys.exit()23
24f = open(songs_list_path, 'r')25songs = f.readlines()26
27if not len(songs):28nt.notify(29title="Mp3 Songs Automatic Downloader",30message='Songs list empty!',31timeout=732)33sys.exit()34
35chrome_options = webdriver.ChromeOptions()36chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])37driver = webdriver.Chrome(38executable_path="C:\\chromedriver.exe", options=chrome_options)39
40driver.get("https://mp3quack.lol/")41
42for song in songs:43driver.find_element_by_id("searchInput").clear()44search = driver.find_element_by_id("searchInput")45search.send_keys(song.strip())46search.send_keys(Keys.RETURN)47time.sleep(2)48download = driver.find_element_by_xpath(49"/html/body/div[2]/div[3]/div/div[2]/div[2]/ul[1]/li[3]")50download.click()51handles = driver.window_handles52driver.switch_to.window(handles[0])53if len(handles) > 1:54for i in range(1, len(handles)):55driver.switch_to.window(handles[i])56driver.close()57driver.switch_to.window(handles[0])58download = driver.find_element_by_xpath(59"/html/body/div[2]/div[3]/div/div[2]/div[2]/ul[1]/li[3]")60download.click()61time.sleep(2)62handles = driver.window_handles63driver.switch_to.window(handles[1])64song_link = driver.find_element_by_xpath(65"/html/body/div[1]/div[2]/div/div[2]/div[3]/ul/li[1]")66song_link.click()67time.sleep(2)68driver.switch_to.window(handles[1])69driver.close()70time.sleep(2)71driver.switch_to.window(handles[0])72
73while True:74count = 075for file in os.listdir(path_to_downloads):76if file.strip().endswith(".crdownload"):77count += 178if count == 0:79break80driver.quit()81f.close()82os.remove(songs_list_path)83