From eaf107d0d2080cf56612f2bdfddcd08e14552538 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 8 Nov 2021 14:54:17 +0700 Subject: [PATCH] add new ta_playlist index and task to find playlists of channel --- tubearchivist/home/src/index.py | 5 ++++- tubearchivist/home/src/index_management.py | 9 +++++++++ tubearchivist/home/tasks.py | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index f2d16d3..9022f26 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -509,10 +509,13 @@ class YoutubePlaylist: all_members = [] for idx, entry in enumerate(playlist["entries"]): + uploader = entry["uploader"] + if not uploader: + continue to_append = { "youtube_id": entry["id"], "title": entry["title"], - "uploader": entry["uploader"], + "uploader": uploader, "idx": idx, } all_members.append(to_append) diff --git a/tubearchivist/home/src/index_management.py b/tubearchivist/home/src/index_management.py index b2286d8..a7046b2 100644 --- a/tubearchivist/home/src/index_management.py +++ b/tubearchivist/home/src/index_management.py @@ -154,6 +154,15 @@ INDEX_CONFIG = [ "number_of_replicas": "0", }, }, + { + "index_name": "playlist", + "expected_map": { + "playlist_description": {"type": "text"}, + }, + "expected_set": { + "number_of_replicas": "0", + }, + }, ] diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index 863d7bd..c69bf18 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -10,6 +10,7 @@ from celery import Celery, shared_task from home.src.config import AppConfig from home.src.download import ChannelSubscription, PendingList, VideoDownloader from home.src.helper import RedisArchivist, RedisQueue, UrlListParser +from home.src.index import YoutubeChannel, YoutubePlaylist from home.src.index_management import backup_all_indexes, restore_from_backup from home.src.reindex import ( ManualImport, @@ -198,3 +199,15 @@ def subscribe_to(url_str): RedisArchivist().set_message( "progress:subscribe", {"status": "subscribing"} ) + + +@shared_task() +def index_channel_playlists(channel_id): + """add all playlists of channel to index""" + channel_handler = YoutubeChannel(channel_id) + all_playlists = channel_handler.get_all_playlists() + + for playlist_id, playlist_title in all_playlists: + print("add playlist: " + playlist_title) + playlist_handler = YoutubePlaylist(playlist_id) + playlist_handler.upload_to_es()