Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

delete incomplete file and retry after downloading failed; check exists file downloaded. #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import multiprocessing
import os
import sys
import time
import urllib.request
from functools import partial

Expand All @@ -31,7 +32,21 @@

def _download(video_url, download_folder):
save_path = os.path.join(download_folder, os.path.basename(video_url))
urllib.request.urlretrieve(video_url, save_path)
if not os.path.exists(save_path):
try_times = 11
while try_times > 0:
try:
try_times = try_times - 1
urllib.request.urlretrieve(video_url, save_path)
except:
if os.path.exists(save_path):
os.remove(save_path)
time.sleep(0.1)
if try_times == 0:
sys.stderr.write(f'\ndownload url: {video_url} failed after retry 10 times.\n')
continue
else:
break

if __name__ == '__main__':
parser = argparse.ArgumentParser(
Expand Down