从songtaste.com上下载歌曲..,songtaste.com,import sys,u
文章由Byrx.net分享于2019-03-23 07:03:18
从songtaste.com上下载歌曲..,songtaste.com,import sys,u
import sys,urllib,re,os,time,string,mathfrom time import strftime,localtime,mktime,clockdef main(): args = sys.argv[1:] if len(args) == 0 : print 'not correct arguments..' sys.exit(0) if len(args) == 1 : a = args[0].strip().lower() # if txt file if args[0].endswith('.txt'): f = open(args[0], 'r') for line in f : id = line.replace("\\n", "").strip() if id == '': continue else: run(int(id))def run(mp3id): start = time.clock() response = urllib.urlopen("<a href="http://songtaste.com/song/">http://songtaste.com/song/" + str(mp3id) + "/") Result = response.read() list = re.findall(r"'player', '([^']+)'.*?(<a href="http://">http://\\d+\\.)'",Result, re.S) if len(list[0]) != 2 : return urllib.urlretrieve(list[0][1] + list[0][0] + '.mp3', './download/'+ str(mp3id) +'.mp3', downloading) print 'end..', 'cost time : ' + str(math.floor(time.clock() - start)) + 'seconds!'def downloading(a, b, c): if a == 0 : print "download begin ..." prec = 100.0*a*b/c if 100 < prec: prec = 100 print "%.2f%%"%(prec,)if __name__ == "__main__": main()#该片段来自于http://byrx.net
评论关闭