-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-mp3-downloader.py
298 lines (254 loc) · 8.22 KB
/
easy-mp3-downloader.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
from bs4 import BeautifulSoup #importing beautifulSoup
import requests
import urllib
import os
import sys
import time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def title():
print('')
print(' -------- EASY MP3 DOWNLOADER --------')
print('')
print('')
def main_menu():
title()
try:
print(' ---------------')
print(' |- Main Menu -|')
print(' ---------------')
print('')
print(' 1. Latest Punjabi Songs')
print(' 2. Latest Hindi Songs')
print(' 3. Latest English Songs')
print(' 4. Exit')
print('')
user_choice=int(input('Input Choice = '))
sub_menu(user_choice)
except:
print('')
print(' -- Please input any one choice from above only--')
print('')
enter=raw_input(' Press enter to try again')
os.system('cls')
os.system('clear')
main_menu()
def sub_menu(user_choice):
os.system('cls')
os.system('clear')
if (user_choice==1):
title()
print(' ------------------------------------')
print(' |- Latest Punjabi Songs - MP3|320Kbps|')
print(' ------------------------------------')
print('')
function_top_punjabi()
elif (user_choice==2):
title()
print(' ----------------------------------')
print(' |- Latest Hindi Songs - MP3|320Kbps|')
print(' ----------------------------------')
print('')
obj=Hindi()
obj.function_top_hindi()
elif (user_choice==3):
title()
print(' ------------------------------------')
print(' |- Latest English Songs - MP3|320Kbps|')
print(' ------------------------------------')
print('')
obj=English()
obj.function_top_english()
elif (user_choice==4):
title()
print(' ----------')
print(' |- Exit -|')
print(' ----------')
print('')
function_exit()
else:
print('')
enter=raw_input(' -- Invalid option selected... Press enter to try again --')
print('')
main_menu()
def function_top_punjabi():
try:
print('-- Please wait while list of top Punjabi songs is getting populated\n')
time.sleep(.300)
url="https://djpunjab.com/page/top20.html?download=320&type=week" #url to the final download page
data=requests.get(url,verify=False)
soup_data=BeautifulSoup(data.content)
count=1
song_name_dict={}
song_link_dict={}
print('------------------------------------')
print('-| Top Punjabi Songs of this week |-')
print('------------------------------------\n')
for link in soup_data.find_all('a'):
download_link=link.get('href')
if '.mp3' in download_link:
link_dict=download_link.split('/')
song_name=link_dict[-1][:-19]
song_link_dict.update({count:download_link})
song_name_dict.update({count:song_name})
print(str(count)+'. '+song_name)
count+=1
time.sleep(.300)
i=1
while (i<count):
file_download(i,song_name_dict[i],song_link_dict[i])
i+=1
time.sleep(.500)
continue
print('')
print('-----------------------------------------')
print(' -- DOWNLOAD COMPLETE --')
print('-----------------------------------------')
print('')
function_exit()
x=raw_input('Press "Enter" to exit.')
except:
connection_error()
class Hindi:
page_link_list=[]
def function_top_hindi(self):
try:
print('-- Please wait while list of top Hindi songs is getting populated\n')
time.sleep(.300)
url="https://djpunjab.com/latest-bollywood-top-songs.html"
data=requests.get(url,verify=False)
soup_data=BeautifulSoup(data.content)
count=1
song_name_dict={}
song_id_dict={}
print('------------------------------------')
print('-| Top Hindi Songs of this week |-')
print('------------------------------------\n')
for link in soup_data.find_all('a'):
page_url=link.get('href')
if 'mp3-song' in page_url:
song_id = page_url.split('-')[-1].strip('.html')
#Hindi.page_link_list.append("https://djpunjab.com"+page_url)
song_name_dict.update({count:link.text})
song_id_dict.update({count:song_id})
print(str(count)+'. '+link.text)
count+=1
time.sleep(.300)
for x in range(1,count):
song_url = self.request_song_link(song_id_dict[x])
file_download(x,song_name_dict[x],song_url)
time.sleep(.500)
print('')
print('-----------------------------------------')
print(' -- DOWNLOAD COMPLETE --')
print('-----------------------------------------')
print('')
function_exit()
x=raw_input('Press "Enter" to exit.')
except Exception,e:
print str(e)
connection_error()
def request_song_link(self,song_id):
page = 'https://www.djpunjab.net/page/direct_url.php?track_id='+song_id
data=requests.get(page,verify=False)
soup_data=BeautifulSoup(data.content)
return soup_data.find(id="textfield6").get('value')
class English():
song_name_dict={}
def function_top_english(self):
try:
print('-- Please wait while list of top English songs is getting populated\n')
time.sleep(.300)
url="https://m.songslover.club/best-of-the-month.html" #url to the final download page
data=requests.get(url,verify=False)
soup_data=BeautifulSoup(data.content)
all_links = soup_data.find_all('div',attrs={'class':'post-inner'})
best_of_links = all_links[0].find_all('a')
album_url=''
for link in best_of_links:
if 'BEST OF' in link.text.upper():
album_url=link['href']
break
if album_url=='':
connection_error()
return
songs_page = requests.get(album_url)
soup_data2 = BeautifulSoup(songs_page.content)
count=1
song_link_dict={}
print('------------------------------------')
print('-| Top English Songs of this week |-')
print('------------------------------------\n')
#for name in soup_data.find_all('span'):
for name in soup_data2.find_all('a'):
if '.mp3' in name['href']:
song = name.text.encode('ascii','ignore').replace(' ',' - ').replace('Download ','')
url = name['href']
English.song_name_dict.update({count:[song,url]})
print(str(count)+'. '+song)
count+=1
time.sleep(.300)
if count>30:
break
i=1
for x in range(1,count):
file_download(x,English.song_name_dict[x][0],'*')
time.sleep(.500)
print('')
print('-----------------------------------------')
print(' -- DOWNLOAD COMPLETE --')
print('-----------------------------------------')
print('')
function_exit()
x=raw_input('Press "Enter" to exit.')
except Exception,e:
print str(e)
connection_error()
def request_song_link(self,count):
url=English.song_name_dict[count][1]
return url
def function_exit():
print('')
print(' -------------------------------------------')
print(' Thankyou for choosing EASY MP3 DOWNLOADER !')
print('')
print(' Fork Me @ GITHUB => Anirudh Sethi - https://github.com/ani10030/')
print(' ----------------------------------------------------------------')
print('')
def file_download(count,song_name,download_link):
try:
file=open(song_name+'.mp3')
file.close()
print ('\n'+'\n'+' '+str(count)+'. '+song_name+'.mp3')
print (' ...FILE ALREADY EXISTS...')
print ('')
except:
print ('\n'+'\n'+' '+str(count)+'. '+song_name+'.mp3')
print (' FETCHING '+'"'+song_name+'.mp3'+'"')
print ('')
if(download_link=='-'):
obj=Hindi()
download_link=obj.request_song_link()
urllib.urlretrieve(download_link,song_name+".mp3",reporthook=download_percent)
elif(download_link=='*'):
obj=English()
download_link=obj.request_song_link(count)
urllib.urlretrieve(download_link,song_name+".mp3",reporthook=download_percent)
else:
urllib.urlretrieve(download_link,song_name+".mp3",reporthook=download_percent)
def connection_error():
print('')
print('ERROR : 504 - Connection Time-Out')
print('---------------------------------')
print('[-] The link you are trying to access is either not responding or taking too long to respond.')
print('[-] Please check your internet connection and try again.')
print('')
print('')
def download_percent(count, blockSize, totalSize):
percent = int(count*blockSize*100/totalSize)
if count*blockSize<=totalSize:
sys.stdout.write('\t[+] '+str(percent)+'% --> '+ str((count*blockSize)/1024) + " Kb of " + str(int(totalSize)/1024) + " Kb"+" Downloaded\r")
else:
sys.stdout.write('\t[-] '+str(percent)+'% --> '+ str((totalSize)/1024) + " Kb of " + str(int(totalSize)/1024) + " Kb"+" Downloaded\r")
sys.stdout.flush()
abc=main_menu()