catch exception in url_info(), fix xiami download error #146

This commit is contained in:
gongqijian 2013-04-13 02:15:18 +08:00
parent a26da57c52
commit e10068f656
2 changed files with 14 additions and 5 deletions

View File

@ -134,10 +134,13 @@ def url_info(url, faker = False):
else:
type = None
if headers['content-disposition']:
filename = parse.unquote(r1(r'filename="?(.+)"?', headers['content-disposition']))
if len(filename.split('.')) > 1:
ext = filename.split('.')[-1]
else:
try:
filename = parse.unquote(r1(r'filename="?(.+)"?', headers['content-disposition']))
if len(filename.split('.')) > 1:
ext = filename.split('.')[-1]
else:
ext = None
except:
ext = None
else:
ext = None

View File

@ -43,6 +43,8 @@ def xiami_download_song(sid, output_dir = '.', merge = True, info_only = False):
url = location_dec(i.getElementsByTagName("location")[0].firstChild.nodeValue)
lrc_url = i.getElementsByTagName("lyric")[0].firstChild.nodeValue
type, ext, size = url_info(url, faker = True)
if not ext:
ext = 'mp3'
print_info(site_info, song_title, type, size)
if not info_only:
@ -66,6 +68,8 @@ def xiami_download_showcollect(cid, output_dir = '.', merge = True, info_only =
url = location_dec(i.getElementsByTagName("location")[0].firstChild.nodeValue)
lrc_url = i.getElementsByTagName("lyric")[0].firstChild.nodeValue
type, ext, size = url_info(url, faker = True)
if not ext:
ext = 'mp3'
print_info(site_info, song_title, type, size)
if not info_only:
@ -88,7 +92,9 @@ def xiami_download_album(aid, output_dir = '.', merge = True, info_only = False)
url = location_dec(i.getElementsByTagName("location")[0].firstChild.nodeValue)
lrc_url = i.getElementsByTagName("lyric")[0].firstChild.nodeValue
type, ext, size = url_info(url, faker = True)
if not ext:
ext = 'mp3'
print_info(site_info, song_title, type, size)
if not info_only:
file_name = "%02d.%s" % (track_nr, song_title)