-
Notifications
You must be signed in to change notification settings - Fork 4
/
ppang_radio_down.py
207 lines (151 loc) · 5.77 KB
/
ppang_radio_down.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#! python3
# test.py - Launches a map in the browser using an address from the
# Windows execute(Win+R) or command line. (https://mp3juices.cc)
import os, sys, pyperclip
from time import sleep
import re
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import ElementNotSelectableException
from selenium.common.exceptions import ElementNotVisibleException
from selenium.webdriver.common.action_chains import ActionChains
def openWebsite(mp3Link):
# Open chrome using webdriver module
global browser
browser = webdriver.Chrome()
browser.get(mp3Link)
def downFunc():
mp3_links = open('yang_radio.txt', 'w+')
for i in range(page_num-1):
nextElem = browser.find_elements_by_css_selector('img[alt="다음"]')[i]
nextElem.click()
sleep(1)
for i in range(page_num-2, -1, -1):
prevElem = browser.find_elements_by_css_selector('img[alt="이전"]')[i]
prevElem.click()
sleep(1)
episode_count = 0
for col in range(page_num):
for row in range(10):
# Click download button
#songElem = browser.find_element_by_id('query')
sleep(1)
songElem = browser.find_elements_by_css_selector('p.download')[episode_count]
sleep(1)
songElem.click()
print('Opened new tab\n')
# Used for keyboard operation!
actions = ActionChains(browser)
# Switch to second tab, and then download .mp3 files
browser.switch_to_window(browser.window_handles[1])
sleep(3)
'''
actions.key_down(Keys.CONTROL)
actions.send_keys(Keys.CONTROL + 's')
actions.key_up(Keys.CONTROL)
actions.send_keys(Keys.ENTER)
sleep(1)
'''
# Store mp3 links to use wget command in linux machine
findMp3Link = browser.find_element_by_css_selector('source[type="audio/mpeg"]')
mp3_link = findMp3Link.get_attribute('src')
#print(mp3_link)
mp3_links.write(mp3_link + '\n')
browser.close()
# Switch back to the original window(or link, whatever)
browser.switch_to_window(browser.window_handles[0])
print('Download %sth episode complete...\n' % episode_count)
episode_count += 1
sleep(1)
nextElem = browser.find_elements_by_css_selector('img[alt="다음"]')[col]
nextElem.click()
print('Moved to the next page!')
mp3_links.close()
def debugging2():
for i in range(2):
nextElem = browser.find_elements_by_css_selector('img[alt="다음"]')[i]
nextElem.click()
sleep(1)
for i in range(1, -1, -1):
prevElem = browser.find_elements_by_css_selector('img[alt="이전"]')[i]
prevElem.click()
sleep(1)
nextElem = browser.find_elements_by_css_selector('img[alt="다음"]')[0]
nextElem.click()
songElem = browser.find_elements_by_css_selector('p.download')[10]
sleep(1)
songElem.click()
def debugging():
nextElem = browser.find_element_by_css_selector('img[alt="다음"]')
nextElem.click()
sleep(1)
prevElem = browser.find_element_by_css_selector('img[alt="이전"]')
prevElem.click()
sleep(1)
nextElem = browser.find_element_by_css_selector('img[alt="다음"]')
nextElem.click()
sleep(1)
songElem = browser.find_elements_by_css_selector('p.download')[11]
print(songElem)
sleep(1)
print('songElem Element is here : \n')
print(songElem)
songElem.click()
print('Opened new tab\n')
# Used for keyboard operation!
actions = ActionChains(browser)
# Switch to second tab, and then download .mp3 files
browser.switch_to_window(browser.window_handles[1])
sleep(10)
browser.close()
# Switch back to the original window(or link, whatever)
browser.switch_to_window(browser.window_handles[0])
print('Download complete... Move on to the next!\n')
sleep(1)
# Change the mp3Link, any radio you like to get
# mp3 downloading website
mp3Link = 'http://www.podbbang.com/ch/88'
global page_num = 100
# Make user Input and store in the list
keywordList = []
# Enter the song info, seperated by newline, slash or comma
# If you enter 'quit', close the browser
if __name__ == "__main__":
# Welcoming ascii art!
print("""
/|
= = = / |
____| || || |____/ | -_-_-_-_-_-_
|)----| || || |____ |
(( | || || | ))\ | _-_-_-_-_-_-
\\_|_||_||_|_// \ |
\___________/ \|
""")
openWebsite(mp3Link)
sleep(5) # wait for browser to be loaded
downFunc()
#debugging()
#debugging2()
'''
while True:
print('What song do you want to download?')
print("""Downloading multiple files :
Type keywords seperated by slash, comma.
Or, if you copied song names with multiple newlines, Just press enter! :) """)
print('If you want to quit, enter "quit" or type nothing.')
userInput = input()
if userInput == 'quit':
browser.quit()
sys.exit()
else:
if userInput == '':
userInput = pyperclip.paste()
print('Ok, so you typed the following :')
print(userInput)
keywordRegex = re.compile(r'[^,\r\n]+')
keywordList = keywordRegex.findall(userInput)
while (len(keywordList) > 0):
downFunc(keywordList[0])
del keywordList[0]
'''