add new ta_playlist index and task to find playlists of channel

This commit is contained in:
simon 2021-11-08 14:54:17 +07:00
parent 1bfb912d09
commit eaf107d0d2
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 26 additions and 1 deletions

View File

@ -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)

View File

@ -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",
},
},
]

View File

@ -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()