web
http://getlinkmusic.appspot.com/
cach dung
python nhaccuatui.py http://www.nhaccuatui.com/nghe?L=1qNzEgxRjkI8
code:
__author__ = 'tunn1'
import string
import urllib2
import re
from xml.etree.ElementTree import *
import urllib
import urlparse
import sys
def decodeHtmlentities(string):
import re
entity_re = re.compile("&(#?)(\d{1,5}|\w{1,8});")
def substitute_entity(match):
from htmlentitydefs import name2codepoint as n2cp
ent = match.group(2)
if match.group(1) == "#":
return unichr(int(ent))
else:
cp = n2cp.get(ent)
if cp:
return unichr(cp)
else:
return match.group()
return entity_re.subn(substitute_entity, string)[0]
def GetHighRateURL(songkey):
listnhac = []
url = 'http://www.nhaccuatui.com/api/song.ashx'
values = {'action' : 'download',
'songkey' : songkey,
'saveas' : 'Save+Link+As...+' }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
p = re.compile("http.*.mp3")
urlhi = p.search(the_page).group()
return decodeHtmlentities(urlhi)
def nhaccuatui_HighRate(url):
listnhac = []
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
p = re.compile(r"http://[\w\d:#@%/;$()~_?\+-=\\\.&]*ashx([?\d\w=\d]*)")
xmlurl = p.search(the_page).group()
xml = ElementTree()
tree = xml.parse(urllib2.urlopen(xmlurl))
for node in tree.getiterator():
for child in node:
info = child.find('info')
if info != None:
pos = info.text.find("=")
songkey = info.text[pos+1:len(info.text)]
listnhac.append(GetHighRateURL(songkey))
return listnhac
def nhacuatui(url):
listnhac = []
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
p = re.compile(r"http://[\w\d:#@%/;$()~_?\+-=\\\.&]*ashx([?\d\w=\d]*)")
xmlurl = p.search(the_page).group()
xml = ElementTree()
tree = xml.parse(urllib2.urlopen(xmlurl))
for node in tree.getiterator():
for child in node:
location = child.find('location')
if location != None:
listnhac.append(location.text)
return listnhac
if __name__ == "__main__":
if len(sys.argv) != 2: # the program name and the two arguments
sys.exit("python nhaccuatui.py http://www.nhaccuatui.com/nghe?L=1qNzEgxRjkI8")
url = "http://www.nhaccuatui.com/nghe?L=1qNzEgxRjkI8";
listnhac = nhaccuatui_HighRate(sys.argv[1])
for i in listnhac:
print i
15/11/2011
Posted by Nguyễn Ngọc Tú |
kiến thức |
Để lại phản hồi