From a1167bac4eb07fe4830cdb55069fb53c6de1cead Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Nov 2021 16:58:39 +0700 Subject: [PATCH] use same page size for playlist rescan --- tubearchivist/home/src/download.py | 17 ++++++++++------- tubearchivist/home/templates/home/settings.html | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 4550aff..2b0a20b 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -358,10 +358,7 @@ class PlaylistSubscription: """manage the playlist download functionality""" def __init__(self): - config = AppConfig().config - self.es_url = config["application"]["es_url"] - self.es_auth = config["application"]["es_auth"] - self.channel_size = config["subscriptions"]["channel_size"] + self.config = AppConfig().config @staticmethod def get_playlists(subscribed_only=True): @@ -380,6 +377,8 @@ class PlaylistSubscription: def change_subscribe(self, playlist_id, subscribe_status): """change the subscribe status of a playlist""" + es_url = self.config["application"]["es_url"] + es_auth = self.config["application"]["es_auth"] playlist_handler = YoutubePlaylist(playlist_id) playlist_handler.get_playlist_dict() subed_now = playlist_handler.playlist_dict["playlist_subscribed"] @@ -391,12 +390,12 @@ class PlaylistSubscription: # update subscribed status print(f"changing status of {playlist_id} to {subscribe_status}") headers = {"Content-type": "application/json"} - url = f"{self.es_url}/ta_playlist/_update/{playlist_id}" + url = f"{es_url}/ta_playlist/_update/{playlist_id}" payload = json.dumps( {"doc": {"playlist_subscribed": subscribe_status}} ) response = requests.post( - url, data=payload, headers=headers, auth=self.es_auth + url, data=payload, headers=headers, auth=es_auth ) if not response.ok: print(response.text) @@ -415,7 +414,11 @@ class PlaylistSubscription: missing_videos = [] counter = 1 for playlist in all_playlists: - playlist_entries = playlist["playlist_entries"] + size_limit = self.config["subscriptions"]["channel_size"] + if size_limit: + playlist_entries = playlist["playlist_entries"][:size_limit] + else: + playlist_entries = playlist["playlist_entries"] all_missing = [i for i in playlist_entries if not i["downloaded"]] RedisArchivist().set_message( diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 732c9b0..c294f26 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -31,8 +31,8 @@

Subscriptions

-

Current channel page size: {{ config.subscriptions.channel_size }}

- Recent videos to check on check pending, max recommended 50.
+

Current page size: {{ config.subscriptions.channel_size }}

+ Recent videos for channels and playlist to check when running Rescan subscriptions, max recommended 50.
{{ app_form.subscriptions_channel_size }}