better unescape, also unescape in xiami lyrics filename

This commit is contained in:
lilydjwg 2014-04-11 19:51:07 +08:00
parent 36f7cf798f
commit 2bca2e771c
3 changed files with 10 additions and 5 deletions

View File

@ -11,7 +11,7 @@ import platform
import threading import threading
from .version import __version__ from .version import __version__
from .util import log, legitimize, sogou_proxy_server, unescape from .util import log, legitimize, sogou_proxy_server, get_filename, unescape
dry_run = False dry_run = False
force = False force = False
@ -523,8 +523,7 @@ def download_urls(urls, title, ext, total_size, output_dir = '.', refer = None,
traceback.print_exc(file = sys.stdout) traceback.print_exc(file = sys.stdout)
pass pass
title = unescape(title) title = get_filename(title)
title = legitimize(title)
filename = '%s.%s' % (title, ext) filename = '%s.%s' % (title, ext)
filepath = os.path.join(output_dir, filename) filepath = os.path.join(output_dir, filename)
@ -604,7 +603,7 @@ def download_urls_chunked(urls, title, ext, total_size, output_dir = '.', refer
assert ext in ('ts') assert ext in ('ts')
title = legitimize(title) title = get_filename(title)
filename = '%s.%s' % (title, 'ts') filename = '%s.%s' % (title, 'ts')
filepath = os.path.join(output_dir, filename) filepath = os.path.join(output_dir, filename)

View File

@ -29,8 +29,9 @@ def location_dec(str):
def xiami_download_lyric(lrc_url, file_name, output_dir): def xiami_download_lyric(lrc_url, file_name, output_dir):
lrc = get_html(lrc_url, faker = True) lrc = get_html(lrc_url, faker = True)
filename = get_filename(file_name)
if len(lrc) > 0: if len(lrc) > 0:
with open(output_dir + "/" + file_name.replace('/', '-').replace('?', '-') + '.lrc', 'w', encoding='utf-8') as x: with open(output_dir + "/" + filename + '.lrc', 'w', encoding='utf-8') as x:
x.write(lrc) x.write(lrc)
def xiami_download_pic(pic_url, file_name, output_dir): def xiami_download_pic(pic_url, file_name, output_dir):

View File

@ -18,3 +18,8 @@ except ImportError:
return chr(int('0'+s, 16)) return chr(int('0'+s, 16))
else: else:
return chr(int(s)) return chr(int(s))
from .fs import legitimize
def get_filename(htmlstring):
return legitimize(unescape(htmlstring))