Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0ddce6

Browse files
Added code to download multiple songs automatically
1 parent 9962dd7 commit b0ddce6

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

‎mp3 Downloader/music.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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(Path.home(), "Desktop", "Songs List for Automated Download.txt")
12+
13+
if not os.path.exists(songs_list_path):
14+
f_temp = open(songs_list_path, 'w')
15+
f_temp.close()
16+
nt.notify(
17+
title = "Mp3 Songs Automatic Downloader",
18+
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!',
19+
timeout = 15
20+
)
21+
sys.exit()
22+
23+
f = open(songs_list_path, 'r')
24+
songs = f.readlines()
25+
26+
if not len(songs):
27+
nt.notify(
28+
title = "Mp3 Songs Automatic Downloader",
29+
message = 'Songs list empty!',
30+
timeout = 7
31+
)
32+
sys.exit()
33+
34+
chrome_options = webdriver.ChromeOptions()
35+
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
36+
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe", options=chrome_options)
37+
38+
driver.get("https://mp3quack.lol/")
39+
40+
for song in songs:
41+
driver.find_element_by_id("searchInput").clear()
42+
search = driver.find_element_by_id("searchInput")
43+
search.send_keys(song.strip())
44+
search.send_keys(Keys.RETURN)
45+
time.sleep(2)
46+
download = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/div[2]/div[2]/ul[1]/li[3]")
47+
download.click()
48+
handles = driver.window_handles
49+
driver.switch_to.window(handles[0])
50+
if len(handles) > 1:
51+
for i in range(1, len(handles)):
52+
driver.switch_to.window(handles[i])
53+
driver.close()
54+
driver.switch_to.window(handles[0])
55+
download = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/div[2]/div[2]/ul[1]/li[3]")
56+
download.click()
57+
time.sleep(2)
58+
handles = driver.window_handles
59+
driver.switch_to.window(handles[1])
60+
song_link = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/ul/li[1]")
61+
song_link.click()
62+
time.sleep(2)
63+
driver.switch_to.window(handles[1])
64+
driver.close()
65+
time.sleep(2)
66+
driver.switch_to.window(handles[0])
67+
68+
while True:
69+
count = 0
70+
for file in os.listdir(path_to_downloads):
71+
if file.strip().endswith(".crdownload"):
72+
count += 1
73+
if count == 0:
74+
break
75+
driver.quit()
76+
f.close()
77+
os.remove(songs_list_path)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /