show progress message for thumbnail download

This commit is contained in:
simon 2021-10-30 17:06:54 +07:00
parent 29fc5fbda2
commit cc90e437a9

View File

@ -117,7 +117,11 @@ class ThumbManager:
), ),
} }
if img_url: if img_url:
response = requests.get(img_url, stream=True) try:
response = requests.get(img_url, stream=True)
except ConnectionError:
sleep(5)
response = requests.get(img_url, stream=True)
if not response.ok and not response.status_code == 404: if not response.ok and not response.status_code == 404:
print("retry thumbnail download for " + img_url) print("retry thumbnail download for " + img_url)
sleep(5) sleep(5)
@ -136,16 +140,13 @@ class ThumbManager:
def download_vid(self, missing_thumbs, notify=True): def download_vid(self, missing_thumbs, notify=True):
"""download all missing thumbnails from list""" """download all missing thumbnails from list"""
total = len(missing_thumbs) print(f"downloading {len(missing_thumbs)} thumbnails")
print(f"downloading {total} thumbnails") counter = 1
# videos
# counter as update path from v0.0.5, remove in future version
counter = 0
for youtube_id, thumb_url in missing_thumbs: for youtube_id, thumb_url in missing_thumbs:
folder_name = youtube_id[0].lower() folder_path = os.path.join(self.VIDEO_DIR, youtube_id[0].lower())
folder_path = os.path.join(self.VIDEO_DIR, folder_name) thumb_path = os.path.join(
thumb_path_part = self.vid_thumb_path(youtube_id) self.CACHE_DIR, self.vid_thumb_path(youtube_id)
thumb_path = os.path.join(self.CACHE_DIR, thumb_path_part) )
os.makedirs(folder_path, exist_ok=True) os.makedirs(folder_path, exist_ok=True)
img_raw = self.get_raw_img(thumb_url, "video") img_raw = self.get_raw_img(thumb_url, "video")
@ -158,17 +159,18 @@ class ThumbManager:
img_raw.convert("RGB").save(thumb_path) img_raw.convert("RGB").save(thumb_path)
progress = f"{counter}/{len(missing_thumbs)}"
if notify: if notify:
mess_dict = { mess_dict = {
"status": "pending", "status": "pending",
"level": "info", "level": "info",
"title": "Adding to download queue.", "title": "Downloading Thumbnails",
"message": "Downloading Thumbnails...", "message": "Progress: " + progress,
} }
RedisArchivist().set_message("progress:download", mess_dict) RedisArchivist().set_message("progress:download", mess_dict)
if counter % 50 == 0 and counter != 0: if counter % 25 == 0:
print(f"thumbnail progress: {counter}/{total}") print("thumbnail progress: " + progress)
counter = counter + 1 counter = counter + 1
def download_chan(self, missing_channels): def download_chan(self, missing_channels):