fix concurrency issue with subtitle indexing

This commit is contained in:
simon 2022-03-23 16:20:33 +07:00
parent 912c19f6cf
commit bfcc538ed1
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 6 additions and 3 deletions

View File

@ -155,6 +155,8 @@ class Reindex:
return return
video.delete_subtitles() video.delete_subtitles()
video.check_subtitles()
# add back # add back
video.json_data["player"] = player video.json_data["player"] = player
video.json_data["date_downloaded"] = date_downloaded video.json_data["date_downloaded"] = date_downloaded

View File

@ -296,7 +296,6 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
self._add_stats() self._add_stats()
self.add_file_path() self.add_file_path()
self.add_player() self.add_player()
self._check_subtitles()
if self.config["downloads"]["integrate_ryd"]: if self.config["downloads"]["integrate_ryd"]:
self._get_ryd_stats() self._get_ryd_stats()
@ -441,7 +440,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
return True return True
def _check_subtitles(self): def check_subtitles(self):
"""optionally add subtitles""" """optionally add subtitles"""
handler = YoutubeSubtitle(self) handler = YoutubeSubtitle(self)
subtitles = handler.get_subtitles() subtitles = handler.get_subtitles()
@ -451,8 +450,9 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
def delete_subtitles(self): def delete_subtitles(self):
"""delete indexed subtitles""" """delete indexed subtitles"""
path = "ta_subtitle/_delete_by_query?refresh=true"
data = {"query": {"term": {"youtube_id": {"value": self.youtube_id}}}} data = {"query": {"term": {"youtube_id": {"value": self.youtube_id}}}}
_, _ = ElasticWrap("ta_subtitle/_delete_by_query").post(data=data) _, _ = ElasticWrap(path).post(data=data)
def index_new_video(youtube_id): def index_new_video(youtube_id):
@ -462,5 +462,6 @@ def index_new_video(youtube_id):
if not video.json_data: if not video.json_data:
raise ValueError("failed to get metadata for " + youtube_id) raise ValueError("failed to get metadata for " + youtube_id)
video.check_subtitles()
video.upload_to_es() video.upload_to_es()
return video.json_data return video.json_data