forked from dilrajsingh1997/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
music_chart.py
92 lines (74 loc) · 2.67 KB
/
music_chart.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
import re
import urllib
import urllib2
import os
import shutil
from bs4 import BeautifulSoup
from subprocess import call
import ctypes
###################################################################################################
def download_song(url):
print "\n\n\nDownload for your song is starting...\n"
try:
command ="youtube-dl --extract-audio --audio-format mp3 "+url
call(command, shell=False)
result=ctypes.windll.user32.MessageBoxA(0, "Download for your song is complete!", "Alert", 0)
except Exception:
result=ctypes.windll.user32.MessageBoxA(0, "Download failed!", "Alert", 0)
def find_song(textToSearch):
for _ in range(1000):
query = urllib.quote(textToSearch+" video song")
url = "https://www.youtube.com/results?search_query=" + query
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html,'lxml')
vid_url=[]
vid_info=[]
for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}):
vid_url.append('https://www.youtube.com' + vid['href'])
vid_info.append(vid.get_text().encode("utf-8"))
if(len(vid_url)>10):
break
for i in range(len(vid_url)):
result=ctypes.windll.user32.MessageBoxA(0, "Start download for song:\n"+vid_info[i],str(len(vid_url))+" results found!", 3)
if(result == 6):
download_song(vid_url[i])
break
elif(result == 7):
continue
else:
break
##################################################################################################
def page_one():
os.system('cls')
print "Show top hindi songs for:"
types=["today","yesterday","thisweek","thismonth","alltime"]
for i in range(5):
print str(i+1)+'.',types[i]
k=int(raw_input("\nEnter type:"))-1
return types[k]
def page_two(category):
site_address="http://www.songsmp3.com/category/top?type="+category
my_link=urllib2.urlopen(site_address)
soup=BeautifulSoup(my_link,'lxml')
names=[]
artists=[]
for song in soup.find_all("div","link-item"):
for info in song.find("div","link"):
names.append(info.get_text().encode("utf-8"))
for artist in song.find_all("div","item-artist"):
artists.append(artist.get_text().encode("utf-8"))
for i in range(21):
artists[i] = re.sub('[^A-Za-z0-9,]+',' ', artists[i] ) #cleaning artists list...
for _ in range(10):
os.system('cls')
print "Showing top hindi songs for:"+category,'\n'
for i in range(21):
print "%-3s%-60s%-10s%-10s"%("x"+str(i+1),names[i][2:],":::::",artists[i][:50])
n=int(raw_input("\nEnter the song code to download or 0 to go back:"))
if(n):
find_song(names[n-1])
else:
break
for _ in range(10000):
page_two(page_one())