mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 20:00:15 +00:00
consolidate delete thumbnails into ThumbManager class
This commit is contained in:
parent
519c710e7d
commit
29f17680bf
@ -171,16 +171,6 @@ class YoutubeChannel:
|
|||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
def clear_cache(self):
|
|
||||||
"""delete banner and thumb from cache if available"""
|
|
||||||
channel_cache = os.path.join(self.CACHE_DIR, "channels")
|
|
||||||
thumb = os.path.join(channel_cache, self.channel_id + "_thumb.jpg")
|
|
||||||
banner = os.path.join(channel_cache, self.channel_id + "_banner.jpg")
|
|
||||||
if os.path.exists(thumb):
|
|
||||||
os.remove(thumb)
|
|
||||||
if os.path.exists(banner):
|
|
||||||
os.remove(banner)
|
|
||||||
|
|
||||||
def sync_to_videos(self):
|
def sync_to_videos(self):
|
||||||
"""sync new channel_dict to all videos of channel"""
|
"""sync new channel_dict to all videos of channel"""
|
||||||
headers = {"Content-type": "application/json"}
|
headers = {"Content-type": "application/json"}
|
||||||
@ -235,6 +225,7 @@ class YoutubeChannel:
|
|||||||
video_path = os.path.join(folder_path, video)
|
video_path = os.path.join(folder_path, video)
|
||||||
os.remove(video_path)
|
os.remove(video_path)
|
||||||
os.rmdir(folder_path)
|
os.rmdir(folder_path)
|
||||||
|
ThumbManager().delete_chan_thumb(self.channel_id)
|
||||||
|
|
||||||
print("delete indexed videos")
|
print("delete indexed videos")
|
||||||
self.delete_es_videos()
|
self.delete_es_videos()
|
||||||
@ -382,13 +373,6 @@ class YoutubeVideo:
|
|||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
def delete_cache(self):
|
|
||||||
"""delete thumbnail from cache if exist"""
|
|
||||||
video_cache = os.path.join(self.CACHE_DIR, "videos")
|
|
||||||
thumb = os.path.join(video_cache, self.youtube_id + ".jpg")
|
|
||||||
if os.path.exists(thumb):
|
|
||||||
os.remove(thumb)
|
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
"""deactivate document on extractor error"""
|
"""deactivate document on extractor error"""
|
||||||
youtube_id = self.youtube_id
|
youtube_id = self.youtube_id
|
||||||
@ -415,7 +399,7 @@ class YoutubeVideo:
|
|||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
# delete thumbs from cache
|
# delete thumbs from cache
|
||||||
self.delete_cache()
|
ThumbManager().delete_vid_thumb(self.youtube_id)
|
||||||
|
|
||||||
|
|
||||||
class WatchState:
|
class WatchState:
|
||||||
|
@ -24,6 +24,7 @@ from home.src.helper import (
|
|||||||
ignore_filelist,
|
ignore_filelist,
|
||||||
)
|
)
|
||||||
from home.src.index import YoutubeChannel, YoutubeVideo, index_new_video
|
from home.src.index import YoutubeChannel, YoutubeVideo, index_new_video
|
||||||
|
from home.src.thumbnails import ThumbManager
|
||||||
|
|
||||||
|
|
||||||
class Reindex:
|
class Reindex:
|
||||||
@ -162,7 +163,7 @@ class Reindex:
|
|||||||
vid_handler.vid_dict["channel"] = channel_dict
|
vid_handler.vid_dict["channel"] = channel_dict
|
||||||
# update
|
# update
|
||||||
vid_handler.upload_to_es()
|
vid_handler.upload_to_es()
|
||||||
vid_handler.delete_cache()
|
ThumbManager().delete_vid_thumb(youtube_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reindex_single_channel(channel_id):
|
def reindex_single_channel(channel_id):
|
||||||
@ -175,7 +176,7 @@ class Reindex:
|
|||||||
channel_handler.channel_dict["channel_subscribed"] = subscribed
|
channel_handler.channel_dict["channel_subscribed"] = subscribed
|
||||||
channel_handler.upload_to_es()
|
channel_handler.upload_to_es()
|
||||||
channel_handler.sync_to_videos()
|
channel_handler.sync_to_videos()
|
||||||
channel_handler.clear_cache()
|
ThumbManager().delete_chan_thumb(channel_id)
|
||||||
|
|
||||||
def reindex(self):
|
def reindex(self):
|
||||||
"""reindex what's needed"""
|
"""reindex what's needed"""
|
||||||
|
@ -156,6 +156,22 @@ class ThumbManager:
|
|||||||
thumb_path = os.path.join(folder_path, youtube_id + ".jpg")
|
thumb_path = os.path.join(folder_path, youtube_id + ".jpg")
|
||||||
return thumb_path
|
return thumb_path
|
||||||
|
|
||||||
|
def delete_vid_thumb(self, youtube_id):
|
||||||
|
"""delete video thumbnail if exists"""
|
||||||
|
thumb_path = self.vid_thumb_path(youtube_id)
|
||||||
|
to_delete = os.path.join(self.CACHE_DIR, thumb_path)
|
||||||
|
if os.path.exists(to_delete):
|
||||||
|
os.remove(to_delete)
|
||||||
|
|
||||||
|
def delete_chan_thumb(self, channel_id):
|
||||||
|
"""delete all artwork of channel"""
|
||||||
|
thumb = os.path.join(self.CHANNEL_DIR, channel_id + "_thumb.jpg")
|
||||||
|
banner = os.path.join(self.CHANNEL_DIR, channel_id + "_banner.jpg")
|
||||||
|
if os.path.exists(thumb):
|
||||||
|
os.remove(thumb)
|
||||||
|
if os.path.exists(banner):
|
||||||
|
os.remove(banner)
|
||||||
|
|
||||||
|
|
||||||
def validate_thumbnails():
|
def validate_thumbnails():
|
||||||
"""check if all thumbnails are there and organized correctly"""
|
"""check if all thumbnails are there and organized correctly"""
|
||||||
|
Loading…
Reference in New Issue
Block a user