From bd37b653c21b30d02fb4a64bec26dae06c4e0885 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 6 Nov 2021 22:30:39 +0700 Subject: [PATCH] extend playlists to get all playlists of a channel and upload single playlist to index --- tubearchivist/home/src/index.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index 732f4ed..f2d16d3 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -245,6 +245,22 @@ class YoutubeChannel: if not response.ok: print(response.text) + def get_all_playlists(self): + """get all playlists owned by this channel""" + url = ( + f"https://www.youtube.com/channel/{self.channel_id}" + + "/playlists?view=1&sort=dd&shelf_id=0" + ) + obs = { + "quiet": True, + "skip_download": True, + "extract_flat": True, + } + playlists = youtube_dl.YoutubeDL(obs).extract_info(url) + all_entries = [(i["id"], i["title"]) for i in playlists["entries"]] + + return all_entries + class YoutubeVideo: """represents a single youtube video""" @@ -503,6 +519,16 @@ class YoutubePlaylist: return all_members + def upload_to_es(self): + """add playlist to es with its entries""" + playlist = self.get_playlist_dict() + playlist["playlist_entries"] = self.get_entries() + + url = f"{self.ES_URL}/ta_playlist/_doc/{self.playlist_id}" + response = requests.put(url, json=playlist, auth=self.ES_AUTH) + if not response.ok: + print(response.text) + class WatchState: """handle watched checkbox for videos and channels"""