rssVideos: Don't download already downloaded videos

Because the good extension is not the one expected :/
This commit is contained in:
Geoffrey Frogeye 2021-12-12 13:40:24 +01:00
parent 8e74f06164
commit 9493edc1fd
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8

View file

@ -41,10 +41,12 @@ def configure_logging(args: configargparse.Namespace) -> None:
logger=log, logger=log,
) )
class RVCommand(enum.Enum): class RVCommand(enum.Enum):
download = "download" download = "download"
list = "list" list = "list"
class RVElement: class RVElement:
title: str title: str
link: str link: str
@ -54,6 +56,7 @@ class RVElement:
guid: int guid: int
parent: "RVDatabase" parent: "RVDatabase"
was_downloaded: bool
def __init__(self, parent: "RVDatabase", item: minidom.Element) -> None: def __init__(self, parent: "RVDatabase", item: minidom.Element) -> None:
def get_data(tag_name: str) -> str: def get_data(tag_name: str) -> str:
@ -75,11 +78,14 @@ class RVElement:
self.guid = int(get_data("guid")) self.guid = int(get_data("guid"))
self.parent = parent self.parent = parent
self.was_downloaded = False
def read_cache(self, cache: "RVElement") -> None: def read_cache(self, cache: "RVElement") -> None:
if "ytdl_infos" in cache.__dict__: if "ytdl_infos" in cache.__dict__:
self.__dict__["ytdl_infos"] = cache.__dict__["ytdl_infos"] self.__dict__["ytdl_infos"] = cache.__dict__["ytdl_infos"]
log.debug(f"From cache: {self}") log.debug(f"From cache: {self}")
if cache.was_downloaded:
self.was_downloaded = True
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.title} {self.link}" return f"{self.title} {self.link}"
@ -131,6 +137,7 @@ class RVElement:
@property @property
def filepath(self) -> str: def filepath(self) -> str:
assert self.is_video 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) return self.parent.ytdl_dry.prepare_filename(self.ytdl_infos)
@property @property
@ -141,16 +148,20 @@ class RVElement:
def download(self) -> None: def download(self) -> None:
assert self.is_video assert self.is_video
log.info(f"Downloading: {self}") log.info(f"Downloading: {self}")
if self.parent.args.dryrun: if not self.parent.args.dryrun:
return self.parent.ytdl.process_ie_result(self.ytdl_infos, True, {})
self.parent.ytdl.process_ie_result(self.ytdl_infos, True, {}) self.was_downloaded = True
self.parent.save()
def act(self) -> None: def act(self) -> None:
if not self.is_video: if not self.is_video:
log.debug(f"Not a video: {self}") log.debug(f"Not a video: {self}")
return return
if self.downloaded: 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 return
if self.skip: if self.skip:
log.debug(f"Skipped: {self}") log.debug(f"Skipped: {self}")
@ -168,6 +179,7 @@ class RVDatabase:
self.args = args self.args = args
def save(self) -> None: def save(self) -> None:
log.debug("Saving cache")
if self.args.dryrun: if self.args.dryrun:
return return
with open(self.SAVE_FILE, "wb") as save_file: with open(self.SAVE_FILE, "wb") as save_file:
@ -205,7 +217,7 @@ class RVDatabase:
def clean(self) -> None: def clean(self) -> None:
filenames = set() filenames = set()
for element in self.elements: for element in self.elements:
if element.is_video: if element.is_video and not element.skip:
filenames.add(element.filename) filenames.add(element.filename)
for file in os.listdir(): for file in os.listdir():
if file == RVDatabase.SAVE_FILE: if file == RVDatabase.SAVE_FILE: