一段下载魔兽世界历史音频的代码

有一位强人做了魔兽世界历史的朗读版本,效果非常不错
可以用以下的代码来下载这些音频
#!/usr/bin/python
# -*- coding: mbcs -*-
import urllib2
import re
# Code By : LiJia, http://blog.csdn.net/imjj
# Date : 2007-05-04
# Purpose : download wow history audio
def get_view_list(nga_url):
f = urllib2.urlopen(nga_url)
#f = open(nga_url)
r = re.compile("/[url=(http://www/.Maidee/.com/program//d+)/](.+?)/[/url/]", re.I)
view_map = {}
for line in f:
ms = r.findall(line)
i = 1
for m in ms:
mp3_name = "%03d.%s" % (i, m[1])
view_map[m[0]] = mp3_name
i += 1
return view_map
def get_mp3_url(view_url):
f = urllib2.urlopen(view_url)
#f = open(view_url)
r = re.compile("http://www/.Maidee/.com/play/.php/?id=/d+", re.I)
for line in f:
m = r.search(line)
if m != None:
return m.group(0)
return ""
def download(url, local_filename):
remote_file = urllib2.urlopen(url)
local_file = open(local_filename, "wb")
print "下载 %s 到 %s" % (url, local_filename),
fsize = int(remote_file.info()["Content-Length"])
print "%d 字节..." % fsize
unitsize = fsize / 25
readsize = 0
i = 1
data = remote_file.read(1024)
while len(data) == 1024:
local_file.write(data)
readsize += len(data)
if readsize > i * unitsize:
print "=",
i += 1
data = remote_file.read(1024)
local_file.write(data)
print "="
print "读取文件列表"
view_list = get_view_list("http://bbs.ngacn.com/read.php?tid=761316&fpage=1")
print "读取到 %d 文件列表" % len(view_list)
for view_url, mp3_name in view_list.iteritems():
mp3_url = get_mp3_url(view_url)
download(mp3_url, mp3_name + ".mp3")

你可能感兴趣的:(一段下载魔兽世界历史音频的代码)