From f4cb17006b0419a4a8f7c8ef3c784998458eb5e8 Mon Sep 17 00:00:00 2001 From: codepongo Date: Tue, 4 Jun 2013 08:58:03 +0800 Subject: [PATCH] revert xiami --- src/you_get/downloader/xiami.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/you_get/downloader/xiami.py b/src/you_get/downloader/xiami.py index 127da043..82223e06 100644 --- a/src/you_get/downloader/xiami.py +++ b/src/you_get/downloader/xiami.py @@ -7,6 +7,7 @@ from ..common import * from xml.dom.minidom import parseString from urllib import parse +from urllib.error import HTTPError def location_dec(str): head = int(str[0]) @@ -28,7 +29,18 @@ def location_dec(str): return parse.unquote(out).replace("^", "0") def xiami_download_lyric(lrc_url, file_name, output_dir): - lrc = get_html(lrc_url, faker = True) + lrc = '' + for i in range(10): + try: + lrc = get_html(lrc_url, faker = True) + except HTTPError as e: + if e.code == 404 or e.code == 416 or e.code == 504: + print(e.msg) + break + else: + raise e + break + if len(lrc) > 0: with open(output_dir + "/" + file_name.replace('/', '-').replace('?', '-') + '.lrc', 'w', encoding='utf-8') as x: x.write(lrc)