From 9493edc1fd4ead7fb15e18e45571ddca47880920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sun, 12 Dec 2021 13:40:24 +0100 Subject: [PATCH] rssVideos: Don't download already downloaded videos Because the good extension is not the one expected :/ --- config/scripts/rssVideos | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/config/scripts/rssVideos b/config/scripts/rssVideos index c36b861..a59b323 100755 --- a/config/scripts/rssVideos +++ b/config/scripts/rssVideos @@ -41,10 +41,12 @@ def configure_logging(args: configargparse.Namespace) -> None: logger=log, ) + class RVCommand(enum.Enum): download = "download" list = "list" + class RVElement: title: str link: str @@ -54,6 +56,7 @@ class RVElement: guid: int parent: "RVDatabase" + was_downloaded: bool def __init__(self, parent: "RVDatabase", item: minidom.Element) -> None: def get_data(tag_name: str) -> str: @@ -75,11 +78,14 @@ class RVElement: self.guid = int(get_data("guid")) self.parent = parent + self.was_downloaded = False def read_cache(self, cache: "RVElement") -> None: if "ytdl_infos" in cache.__dict__: self.__dict__["ytdl_infos"] = cache.__dict__["ytdl_infos"] log.debug(f"From cache: {self}") + if cache.was_downloaded: + self.was_downloaded = True def __str__(self) -> str: return f"{self.title} – {self.link}" @@ -131,6 +137,7 @@ class RVElement: @property def filepath(self) -> str: assert self.is_video + # TODO This doesn't change the extension to mkv when the formats are incomaptible return self.parent.ytdl_dry.prepare_filename(self.ytdl_infos) @property @@ -141,16 +148,20 @@ class RVElement: def download(self) -> None: assert self.is_video log.info(f"Downloading: {self}") - if self.parent.args.dryrun: - return - self.parent.ytdl.process_ie_result(self.ytdl_infos, True, {}) + if not self.parent.args.dryrun: + self.parent.ytdl.process_ie_result(self.ytdl_infos, True, {}) + self.was_downloaded = True + self.parent.save() def act(self) -> None: if not self.is_video: log.debug(f"Not a video: {self}") return if self.downloaded: - log.debug(f"Already downloaded: {self}") + log.debug(f"Currently downloaded: {self}") + return + if self.was_downloaded: + log.debug(f"Downloaded previously: {self}") return if self.skip: log.debug(f"Skipped: {self}") @@ -168,6 +179,7 @@ class RVDatabase: self.args = args def save(self) -> None: + log.debug("Saving cache") if self.args.dryrun: return with open(self.SAVE_FILE, "wb") as save_file: @@ -205,7 +217,7 @@ class RVDatabase: def clean(self) -> None: filenames = set() for element in self.elements: - if element.is_video: + if element.is_video and not element.skip: filenames.add(element.filename) for file in os.listdir(): if file == RVDatabase.SAVE_FILE: