From 3efdc1962db6db7d565ec92c38add0b5880174b7 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Nov 2021 21:16:18 +0700 Subject: [PATCH] fix playlist nav builder using correct index --- tubearchivist/home/src/index.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index 92117b4..350a2c3 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -261,6 +261,17 @@ class YoutubeChannel: return all_entries + def get_indexed_playlists(self): + """get all indexed playlists from channel""" + data = { + "query": { + "term": {"playlist_channel_id": {"value": self.channel_id}} + }, + "sort": [{"playlist_channel.keyword": {"order": "desc"}}], + } + all_playlists = IndexPaginate("ta_playlist", data).get_results() + return all_playlists + class YoutubeVideo: """represents a single youtube video""" @@ -586,26 +597,26 @@ class YoutubePlaylist: if not current or not len(all_entries) > 1: return False - current_idx = current[0]["idx"] + current_idx = all_entries.index(current[0]) if current_idx == 0: + next_item = False + else: + next_item = all_entries[current_idx - 1] + next_thumb = ThumbManager().vid_thumb_path(next_item["youtube_id"]) + next_item["vid_thumb"] = next_thumb + + if current_idx == len(all_entries) - 1: previous_item = False else: - previous_item = all_entries[current_idx - 1] + previous_item = all_entries[current_idx + 1] prev_thumb = ThumbManager().vid_thumb_path( previous_item["youtube_id"] ) previous_item["vid_thumb"] = prev_thumb - if current_idx == len(all_entries) - 1: - next_item = False - else: - next_item = all_entries[current_idx + 1] - next_thumb = ThumbManager().vid_thumb_path(next_item["youtube_id"]) - next_item["vid_thumb"] = next_thumb - nav = { "playlist_meta": { - "current_idx": current_idx, + "current_idx": current[0]["idx"], "playlist_id": self.playlist_id, "playlist_name": self.playlist_dict["playlist_name"], "playlist_channel": self.playlist_dict["playlist_channel"],