delete comments when deleting video

This commit is contained in:
simon 2022-11-18 10:47:48 +07:00
parent a5be5a719b
commit e590d456a1
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 12 additions and 2 deletions

View File

@ -26,7 +26,7 @@ class Comments:
def build_json(self):
"""build json document for es"""
print(f"{self.youtube_id}: get comments")
self._check_config()
self.check_config()
if not self.is_activated:
return
@ -40,7 +40,7 @@ class Comments:
"comment_comments": self.comments_format,
}
def _check_config(self):
def check_config(self):
"""read config if not attached"""
if not self.config:
self.config = AppConfig().config
@ -127,6 +127,7 @@ class Comments:
def delete_comments(self):
"""delete comments from es"""
print(f"{self.youtube_id}: delete comments")
_, _ = ElasticWrap(self.es_path).delete(refresh=True)
def get_es_comments(self):

View File

@ -11,6 +11,7 @@ import requests
from django.conf import settings
from home.src.es.connect import ElasticWrap
from home.src.index import channel as ta_channel
from home.src.index import comments as ta_comments
from home.src.index import playlist as ta_playlist
from home.src.index.generic import YouTubeItem
from home.src.index.subtitle import YoutubeSubtitle
@ -302,6 +303,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
self.del_in_playlists()
self.del_in_es()
self.delete_subtitles()
self.delete_comments()
def del_in_playlists(self):
"""remove downloaded in playlist"""
@ -326,6 +328,13 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
print(f"{self.youtube_id}: delete subtitles")
YoutubeSubtitle(self).delete(subtitles=subtitles)
def delete_comments(self):
"""delete comments from es"""
comments = ta_comments.Comments(self.youtube_id, config=self.config)
comments.check_config()
if comments.is_activated:
comments.delete_comments()
def _get_ryd_stats(self):
"""get optional stats from returnyoutubedislikeapi.com"""
# pylint: disable=broad-except