refactor comment interface into reusable CommentList class

pull/395/head
simon 2 years ago
parent 0b60377e19
commit 599dd26b53
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

@ -15,7 +15,7 @@ from home.src.download.subscriptions import PlaylistSubscription
from home.src.download.yt_dlp_base import CookieHandler, YtWrap from home.src.download.yt_dlp_base import CookieHandler, YtWrap
from home.src.es.connect import ElasticWrap, IndexPaginate from home.src.es.connect import ElasticWrap, IndexPaginate
from home.src.index.channel import YoutubeChannel from home.src.index.channel import YoutubeChannel
from home.src.index.comments import Comments from home.src.index.comments import CommentList
from home.src.index.playlist import YoutubePlaylist from home.src.index.playlist import YoutubePlaylist
from home.src.index.video import YoutubeVideo, index_new_video from home.src.index.video import YoutubeVideo, index_new_video
from home.src.ta.config import AppConfig from home.src.ta.config import AppConfig
@ -143,25 +143,7 @@ class DownloadPostProcess:
def get_comments(self): def get_comments(self):
"""get comments from youtube""" """get comments from youtube"""
if not self.download.config["downloads"]["comment_max"]: CommentList(self.download.videos).index(send_notifications=True)
return
total_videos = len(self.download.videos)
for idx, video_id in enumerate(self.download.videos):
comment = Comments(video_id, config=self.download.config)
comment.build_json(notify=(idx, total_videos))
if comment.json_data:
comment.upload_comments()
key = "message:download"
message = {
"status": key,
"level": "info",
"title": "Download and index comments finished",
"message": f"added comments for {total_videos} videos",
}
RedisArchivist().set_message(key, message, expire=4)
class VideoDownloader: class VideoDownloader:

@ -14,7 +14,7 @@ from home.src.ta.ta_redis import RedisArchivist
class Comments: class Comments:
"""hold all comments functionality""" """interact with comments per video"""
def __init__(self, youtube_id, config=False): def __init__(self, youtube_id, config=False):
self.youtube_id = youtube_id self.youtube_id = youtube_id
@ -187,3 +187,40 @@ class Comments:
self.delete_comments() self.delete_comments()
self.upload_comments() self.upload_comments()
class CommentList:
"""interact with comments in group"""
def __init__(self, video_ids):
self.video_ids = video_ids
self.config = AppConfig().config
def index(self, notify=False):
"""index group of videos"""
if not self.config["downloads"].get("comment_max"):
return
total_videos = len(self.video_ids)
for idx, video_id in enumerate(self.video_ids):
comment = Comments(video_id, config=self.config)
if notify:
notify = (idx, total_videos)
comment.build_json(notify=notify)
if comment.json_data:
comment.upload_comments()
if notify:
self.notify_final(total_videos)
@staticmethod
def notify_final(total_videos):
"""send final notification"""
key = "message:download"
message = {
"status": key,
"level": "info",
"title": "Download and index comments finished",
"message": f"added comments for {total_videos} videos",
}
RedisArchivist().set_message(key, message, expire=4)

@ -14,6 +14,7 @@ import subprocess
from home.src.download.queue import PendingList from home.src.download.queue import PendingList
from home.src.download.thumbnails import ThumbManager from home.src.download.thumbnails import ThumbManager
from home.src.es.connect import ElasticWrap from home.src.es.connect import ElasticWrap
from home.src.index.comments import CommentList
from home.src.index.video import YoutubeVideo, index_new_video from home.src.index.video import YoutubeVideo, index_new_video
from home.src.ta.config import AppConfig from home.src.ta.config import AppConfig
from home.src.ta.helper import clean_string, ignore_filelist from home.src.ta.helper import clean_string, ignore_filelist
@ -601,6 +602,8 @@ def scan_filesystem():
filesystem_handler.delete_from_index() filesystem_handler.delete_from_index()
if filesystem_handler.to_index: if filesystem_handler.to_index:
print("index new videos") print("index new videos")
for missing_vid in filesystem_handler.to_index: video_ids = [i[2] for i in filesystem_handler.to_index]
youtube_id = missing_vid[2] for youtube_id in video_ids:
index_new_video(youtube_id) index_new_video(youtube_id)
CommentList(video_ids).index()

Loading…
Cancel
Save