add missing local playlist downloaded match, #1092

This commit is contained in:
Simon 2025-11-15 22:46:02 +07:00
parent 2dea80e6b1
commit daa15c0577
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 27 additions and 1 deletions

View File

@ -40,7 +40,7 @@ class DownloaderBase:
PLAYLIST_QUICK = "download:playlist:quick"
VIDEO_QUEUE = "download:video"
def __init__(self, task):
def __init__(self, task=None):
self.task = task
self.config = AppConfig().config
self.channel_overwrites = get_channel_overwrites()
@ -467,6 +467,7 @@ class DownloadPostProcess(DownloaderBase):
playlist.get_from_es()
playlist.add_vids_to_playlist()
playlist.remove_vids_from_playlist()
playlist.match_local()
if not self.task:
continue

View File

@ -197,6 +197,31 @@ class YoutubePlaylist(YouTubeItem):
if status_code == 200:
print(f"{self.youtube_id}: removed {video_id} from playlist")
def match_local(self):
"""match local videos as indexed"""
ids = [i["youtube_id"] for i in self.json_data["playlist_entries"]]
data = {
"query": {"terms": {"youtube_id": ids}},
"_source": ["youtube_id", "title", "channel.channel_name"],
}
local_vids = IndexPaginate("ta_video", data).get_results()
indexed_vids = {i["youtube_id"]: i for i in local_vids}
new_entries = []
for entry in self.json_data["playlist_entries"]:
if local_vid := indexed_vids.get(entry["youtube_id"]):
entry.update(
{
"title": local_vid["title"],
"uploader": local_vid["channel"]["channel_name"],
"downloaded": True,
}
)
new_entries.append(entry)
self.json_data["playlist_entries"] = new_entries
self.upload_to_es()
def update_playlist(self, skip_on_empty=False):
"""update metadata for playlist with data from YouTube"""
self.build_json(scrape=True)