From 76ac5dc93e2384a019bef571592db36e2b34a5cb Mon Sep 17 00:00:00 2001 From: wwwpf <24772538+wwwpf@users.noreply.github.com> Date: Mon, 24 Dec 2018 10:59:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=9B=B8=E5=86=8C=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=B8=AD=E5=90=AB=E6=9C=89=E7=A9=BA=E6=A0=BC=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E5=87=BA=E9=94=99=EF=BC=9B?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E6=97=B6=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- download.py | 4 ++-- tools.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/download.py b/download.py index 7933f97..d87113f 100644 --- a/download.py +++ b/download.py @@ -16,7 +16,7 @@ def download_media(url, dir, file_name): s = "\rdownloading %s -> %05.2f%% " chunk_size = 1024 - with closing(requests.get(url, stream=True)) as r: + with requests.get(url, stream=True, timeout=30) as r: extension = "jpg" if "content-type" in r.headers: content_type = r.headers["content-type"] @@ -36,7 +36,7 @@ def download_media(url, dir, file_name): current_len += len(data) percent = 100 * current_len / total_len print(s % (url, percent), end="") - print("\n%s is downloaded" % url) + print("\n%s is downloaded" % url) @logging_wrap diff --git a/tools.py b/tools.py index f7da76c..361d6be 100644 --- a/tools.py +++ b/tools.py @@ -31,6 +31,10 @@ def get_json_data_from_response(resp_text): def purge_file_name(file_name): + temp = file_name + file_name = "" + for c in temp: + file_name += "_" if c.isspace() else c escape_chars = "/\\:*?\"<>|" for c in escape_chars: file_name = file_name.replace(c, "%%%X" % ord(c)) From f2b625b5cbab2a2142a1e1a4b7d8e6b11cf2cafa Mon Sep 17 00:00:00 2001 From: wwwpf <24772538+wwwpf@users.noreply.github.com> Date: Mon, 24 Dec 2018 11:38:07 +0800 Subject: [PATCH 2/2] fix --- download.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/download.py b/download.py index d87113f..51b475c 100644 --- a/download.py +++ b/download.py @@ -14,6 +14,7 @@ @logging_wrap def download_media(url, dir, file_name): + result = False s = "\rdownloading %s -> %05.2f%% " chunk_size = 1024 with requests.get(url, stream=True, timeout=30) as r: @@ -36,7 +37,9 @@ def download_media(url, dir, file_name): current_len += len(data) percent = 100 * current_len / total_len print(s % (url, percent), end="") + result = True print("\n%s is downloaded" % url) + return result @logging_wrap @@ -115,7 +118,7 @@ def download(self): download_dir = temp[1] id = temp[2] - download_media(url, download_dir, id) - fupdate.write("%s\n" % url) - fupdate.flush() + if download_media(url, download_dir, id): + fupdate.write("%s\n" % url) + fupdate.flush() print("downloading done")