clean up progress hook title and speed up playlist validation

This commit is contained in:
simon 2021-12-05 21:57:33 +07:00
parent 19871d55e2
commit 8874168291
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -587,8 +587,10 @@ class VideoDownloader:
def progress_hook(response): def progress_hook(response):
"""process the progress_hooks from youtube_dl""" """process the progress_hooks from youtube_dl"""
# title # title
filename = response["filename"][12:].replace("_", " ") path = os.path.split(response["filename"])[-1][12:]
title = "Downloading: " + os.path.split(filename)[-1] filename = os.path.splitext(os.path.splitext(path)[0])[0]
filename_clean = filename.replace("_", " ")
title = "Downloading: " + filename_clean
# message # message
try: try:
percent = response["_percent_str"] percent = response["_percent_str"]
@ -597,7 +599,7 @@ class VideoDownloader:
eta = response["_eta_str"] eta = response["_eta_str"]
message = f"{percent} of {size} at {speed} - time left: {eta}" message = f"{percent} of {size} at {speed} - time left: {eta}"
except KeyError: except KeyError:
message = "" message = "processing"
mess_dict = { mess_dict = {
"status": "message:download", "status": "message:download",
"level": "info", "level": "info",
@ -741,12 +743,10 @@ class VideoDownloader:
self.add_subscribed_channels() self.add_subscribed_channels()
all_indexed = PendingList().get_all_indexed() all_indexed = PendingList().get_all_indexed()
all_youtube_ids = [i["youtube_id"] for i in all_indexed] all_youtube_ids = [i["youtube_id"] for i in all_indexed]
c_counter = 1 for id_c, channel_id in enumerate(self.channels):
for channel_id in self.channels:
playlists = YoutubeChannel(channel_id).get_indexed_playlists() playlists = YoutubeChannel(channel_id).get_indexed_playlists()
all_playlist_ids = [i["playlist_id"] for i in playlists] all_playlist_ids = [i["playlist_id"] for i in playlists]
p_counter = 1 for id_p, playlist_id in enumerate(all_playlist_ids):
for playlist_id in all_playlist_ids:
playlist_handler = YoutubePlaylist( playlist_handler = YoutubePlaylist(
playlist_id, all_youtube_ids=all_youtube_ids playlist_id, all_youtube_ids=all_youtube_ids
) )
@ -759,15 +759,18 @@ class VideoDownloader:
# notify # notify
title = ( title = (
"Processing playlists for channels: " "Processing playlists for channels: "
+ f"{c_counter}/{len(self.channels)}" + f"{id_c + 1}/{len(self.channels)}"
) )
message = f"Progress: {p_counter}/{len(all_playlist_ids)}" message = f"Progress: {id_p + 1}/{len(all_playlist_ids)}"
mess_dict = { mess_dict = {
"status": "message:download", "status": "message:download",
"level": "info", "level": "info",
"title": title, "title": title,
"message": message, "message": message,
} }
if id_p + 1 == len(all_playlist_ids):
RedisArchivist().set_message(
"message:download", mess_dict, expire=4
)
else:
RedisArchivist().set_message("message:download", mess_dict) RedisArchivist().set_message("message:download", mess_dict)
p_counter = p_counter + 1
c_counter = c_counter + 1