Amazing-Python-Scripts

Форк
0
82 строки · 2.5 Кб
1
import time
2
import os
3
import sys
4
from pathlib import Path
5
from plyer import notification as nt
6
from selenium import webdriver
7
from selenium.webdriver.common.keys import Keys
8

9
path_to_downloads = os.path.join(Path.home(), "Downloads")
10

11
songs_list_path = os.path.join(
12
    Path.home(), "Desktop", "Songs List for Automated Download.txt")
13

14
if not os.path.exists(songs_list_path):
15
    f_temp = open(songs_list_path, 'w')
16
    f_temp.close()
17
    nt.notify(
18
        title="Mp3 Songs Automatic Downloader",
19
        message='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!',
20
        timeout=15
21
    )
22
    sys.exit()
23

24
f = open(songs_list_path, 'r')
25
songs = f.readlines()
26

27
if not len(songs):
28
    nt.notify(
29
        title="Mp3 Songs Automatic Downloader",
30
        message='Songs list empty!',
31
        timeout=7
32
    )
33
    sys.exit()
34

35
chrome_options = webdriver.ChromeOptions()
36
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
37
driver = webdriver.Chrome(
38
    executable_path="C:\\chromedriver.exe", options=chrome_options)
39

40
driver.get("https://mp3quack.lol/")
41

42
for song in songs:
43
    driver.find_element_by_id("searchInput").clear()
44
    search = driver.find_element_by_id("searchInput")
45
    search.send_keys(song.strip())
46
    search.send_keys(Keys.RETURN)
47
    time.sleep(2)
48
    download = driver.find_element_by_xpath(
49
        "/html/body/div[2]/div[3]/div/div[2]/div[2]/ul[1]/li[3]")
50
    download.click()
51
    handles = driver.window_handles
52
    driver.switch_to.window(handles[0])
53
    if len(handles) > 1:
54
        for i in range(1, len(handles)):
55
            driver.switch_to.window(handles[i])
56
            driver.close()
57
        driver.switch_to.window(handles[0])
58
        download = driver.find_element_by_xpath(
59
            "/html/body/div[2]/div[3]/div/div[2]/div[2]/ul[1]/li[3]")
60
        download.click()
61
    time.sleep(2)
62
    handles = driver.window_handles
63
    driver.switch_to.window(handles[1])
64
    song_link = driver.find_element_by_xpath(
65
        "/html/body/div[1]/div[2]/div/div[2]/div[3]/ul/li[1]")
66
    song_link.click()
67
    time.sleep(2)
68
    driver.switch_to.window(handles[1])
69
    driver.close()
70
    time.sleep(2)
71
    driver.switch_to.window(handles[0])
72

73
while True:
74
    count = 0
75
    for file in os.listdir(path_to_downloads):
76
        if file.strip().endswith(".crdownload"):
77
            count += 1
78
    if count == 0:
79
        break
80
driver.quit()
81
f.close()
82
os.remove(songs_list_path)
83

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.