mirror of
https://github.com/tubearchivist/tubearchivist
synced 2024-11-10 01:10:31 +00:00
fix subtitle delete overwrite, change filename to .lang.vtt, #195
This commit is contained in:
parent
386c456415
commit
bbb0c26498
@ -153,6 +153,7 @@ class Reindex:
|
|||||||
date_downloaded = video.json_data["date_downloaded"]
|
date_downloaded = video.json_data["date_downloaded"]
|
||||||
channel_dict = video.json_data["channel"]
|
channel_dict = video.json_data["channel"]
|
||||||
playlist = video.json_data.get("playlist")
|
playlist = video.json_data.get("playlist")
|
||||||
|
subtitles = video.json_data.get("subtitles")
|
||||||
|
|
||||||
# get new
|
# get new
|
||||||
video.build_json()
|
video.build_json()
|
||||||
@ -160,7 +161,7 @@ class Reindex:
|
|||||||
video.deactivate()
|
video.deactivate()
|
||||||
return
|
return
|
||||||
|
|
||||||
video.delete_subtitles()
|
video.delete_subtitles(subtitles=subtitles)
|
||||||
video.check_subtitles()
|
video.check_subtitles()
|
||||||
|
|
||||||
# add back
|
# add back
|
||||||
|
@ -67,7 +67,7 @@ class YoutubeSubtitle:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
video_media_url = self.video.json_data["media_url"]
|
video_media_url = self.video.json_data["media_url"]
|
||||||
media_url = video_media_url.replace(".mp4", f"-{lang}.vtt")
|
media_url = video_media_url.replace(".mp4", f".{lang}.vtt")
|
||||||
all_formats = all_subtitles.get(lang)
|
all_formats = all_subtitles.get(lang)
|
||||||
if not all_formats:
|
if not all_formats:
|
||||||
return False
|
return False
|
||||||
@ -103,7 +103,7 @@ class YoutubeSubtitle:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
video_media_url = self.video.json_data["media_url"]
|
video_media_url = self.video.json_data["media_url"]
|
||||||
media_url = video_media_url.replace(".mp4", f"-{lang}.vtt")
|
media_url = video_media_url.replace(".mp4", f".{lang}.vtt")
|
||||||
all_formats = all_subtitles.get(lang)
|
all_formats = all_subtitles.get(lang)
|
||||||
if not all_formats:
|
if not all_formats:
|
||||||
# no user subtitles found
|
# no user subtitles found
|
||||||
@ -152,15 +152,19 @@ class YoutubeSubtitle:
|
|||||||
"""send subtitle to es for indexing"""
|
"""send subtitle to es for indexing"""
|
||||||
_, _ = ElasticWrap("_bulk").post(data=query_str, ndjson=True)
|
_, _ = ElasticWrap("_bulk").post(data=query_str, ndjson=True)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self, subtitles=False):
|
||||||
"""delete subtitles from index and filesystem"""
|
"""delete subtitles from index and filesystem"""
|
||||||
youtube_id = self.video.youtube_id
|
youtube_id = self.video.youtube_id
|
||||||
# delete files
|
|
||||||
videos_base = self.video.config["application"]["videos"]
|
videos_base = self.video.config["application"]["videos"]
|
||||||
|
# delete files
|
||||||
|
if subtitles:
|
||||||
|
files = [i["media_url"] for i in subtitles]
|
||||||
|
else:
|
||||||
if not self.video.json_data.get("subtitles"):
|
if not self.video.json_data.get("subtitles"):
|
||||||
return
|
return
|
||||||
|
|
||||||
files = [i["media_url"] for i in self.video.json_data["subtitles"]]
|
files = [i["media_url"] for i in self.video.json_data["subtitles"]]
|
||||||
|
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
file_path = os.path.join(videos_base, file_name)
|
file_path = os.path.join(videos_base, file_name)
|
||||||
try:
|
try:
|
||||||
@ -594,10 +598,10 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
|||||||
)
|
)
|
||||||
playlist.upload_to_es()
|
playlist.upload_to_es()
|
||||||
|
|
||||||
def delete_subtitles(self):
|
def delete_subtitles(self, subtitles=False):
|
||||||
"""delete indexed subtitles"""
|
"""delete indexed subtitles"""
|
||||||
print(f"{self.youtube_id}: delete subtitles")
|
print(f"{self.youtube_id}: delete subtitles")
|
||||||
YoutubeSubtitle(self).delete()
|
YoutubeSubtitle(self).delete(subtitles=subtitles)
|
||||||
|
|
||||||
def _get_ryd_stats(self):
|
def _get_ryd_stats(self):
|
||||||
"""get optional stats from returnyoutubedislikeapi.com"""
|
"""get optional stats from returnyoutubedislikeapi.com"""
|
||||||
|
Loading…
Reference in New Issue
Block a user