mark video as downloaded false when deleting video
This commit is contained in:
parent
e638f8b487
commit
9f92bf95b4
|
@ -12,6 +12,7 @@ import requests
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from home.src.es.connect import ElasticWrap
|
from home.src.es.connect import ElasticWrap
|
||||||
from home.src.index import channel as ta_channel
|
from home.src.index import channel as ta_channel
|
||||||
|
from home.src.index import playlist as ta_playlist
|
||||||
from home.src.index.generic import YouTubeItem
|
from home.src.index.generic import YouTubeItem
|
||||||
from home.src.ta.helper import (
|
from home.src.ta.helper import (
|
||||||
DurationConverter,
|
DurationConverter,
|
||||||
|
@ -561,6 +562,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
||||||
|
|
||||||
def delete_media_file(self):
|
def delete_media_file(self):
|
||||||
"""delete video file, meta data"""
|
"""delete video file, meta data"""
|
||||||
|
print(f"{self.youtube_id}: delete video")
|
||||||
self.get_from_es()
|
self.get_from_es()
|
||||||
video_base = self.app_conf["videos"]
|
video_base = self.app_conf["videos"]
|
||||||
media_url = self.json_data.get("media_url")
|
media_url = self.json_data.get("media_url")
|
||||||
|
@ -570,9 +572,28 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"{self.youtube_id}: failed {media_url}, continue.")
|
print(f"{self.youtube_id}: failed {media_url}, continue.")
|
||||||
|
|
||||||
|
self.del_in_playlists()
|
||||||
self.del_in_es()
|
self.del_in_es()
|
||||||
self.delete_subtitles()
|
self.delete_subtitles()
|
||||||
|
|
||||||
|
def del_in_playlists(self):
|
||||||
|
"""remove downloaded in playlist"""
|
||||||
|
all_playlists = self.json_data.get("playlist")
|
||||||
|
if not all_playlists:
|
||||||
|
return
|
||||||
|
|
||||||
|
for playlist_id in all_playlists:
|
||||||
|
print(f"{playlist_id}: delete video {self.youtube_id}")
|
||||||
|
playlist = ta_playlist.YoutubePlaylist(playlist_id)
|
||||||
|
playlist.get_from_es()
|
||||||
|
entries = playlist.json_data["playlist_entries"]
|
||||||
|
for idx, entry in enumerate(entries):
|
||||||
|
if entry["youtube_id"] == self.youtube_id:
|
||||||
|
playlist.json_data["playlist_entries"][idx].update(
|
||||||
|
{"downloaded": False}
|
||||||
|
)
|
||||||
|
playlist.upload_to_es()
|
||||||
|
|
||||||
def delete_subtitles(self):
|
def delete_subtitles(self):
|
||||||
"""delete indexed subtitles"""
|
"""delete indexed subtitles"""
|
||||||
print(f"{self.youtube_id}: delete subtitles")
|
print(f"{self.youtube_id}: delete subtitles")
|
||||||
|
|
Loading…
Reference in New Issue