rssVideos: Replace guid by date and id

This commit is contained in:
Geoffrey Frogeye 2021-12-29 14:40:00 +01:00
parent c36534f696
commit 8ae5c00f53

View file

@ -8,6 +8,7 @@ The common use case would be a feed from an RSS aggregator
with the unread items (non-video links are ignored).
"""
import datetime
import functools
import logging
import os
@ -26,7 +27,6 @@ import yt_dlp
log = logging.getLogger(__name__)
# TODO Lockfile, or a way to parallel watch and download
# TODO Save ytdl infos and view info separately
def configure_logging(args: configargparse.Namespace) -> None:
@ -131,8 +131,8 @@ class RVElement:
return self.item["origin"]["title"]
@property
def guid(self) -> int:
return int(self.item["timestampUsec"])
def date(self) -> datetime.datetime:
return datetime.datetime.fromtimestamp(self.item["published"])
@property
def is_researched(self) -> bool:
@ -146,16 +146,19 @@ class RVElement:
self.downloaded_filepath = cache.downloaded_filepath
def __str__(self) -> str:
# return self.item.get("id")
str = f"{self.guid}: {self.creator if self.creator else '?'} {self.title}"
str = f"{self.date.strftime('%y-%m-%d %H:%M')} ("
if self.is_researched:
if self.is_video:
str += f" ({format_duration(self.duration)})"
str += format_duration(self.duration)
else:
str += " (N/A)"
str += "--:--:--"
else:
str += " (?)"
str += f" {self.link}"
str += "??:??:??"
str += (
f") {self.creator if self.creator else '?'} "
f" {self.title} "
f" {self.link}"
)
return str
@property
@ -247,9 +250,6 @@ class RVElement:
if args.title and not re.search(args.title, self.title):
log.debug(f"Title not matching {args.title}: {self}")
return False
if args.guid and not re.search(args.guid, str(self.guid)):
log.debug(f"Guid not matching {args.guid}: {self}")
return False
if args.link and not re.search(args.link, self.link):
log.debug(f"Link not matching {args.link}: {self}")
return False
@ -353,18 +353,18 @@ class RVDatabase:
log.debug("Salvaging cache")
cache_els = dict()
for cache_el in cache.elements:
cache_els[cache_el.guid] = cache_el
cache_els[cache_el.id] = cache_el
for el in self.elements:
if el.guid in cache_els:
el.salvage_cache(cache_els[el.guid])
if el.id in cache_els:
el.salvage_cache(cache_els[el.id])
def clean_cache(self, cache: "RVDatabase") -> None:
log.debug("Cleaning cache")
self_els = dict()
for self_el in self.elements:
self_els[self_el.guid] = self_el
self_els[self_el.id] = self_el
for el in cache.elements:
if el.guid not in self_els:
if el.id not in self_els:
if el.is_researched and el.is_video:
el.clean()
@ -600,11 +600,11 @@ def get_args() -> configargparse.Namespace:
default="old",
help="Sorting mechanism",
)
parser.add("--guid", help="Regex to filter guid")
parser.add("--creator", help="Regex to filter by creator")
parser.add("--title", help="Regex to filter by title")
parser.add("--link", help="Regex to filter by link")
parser.add("--duration", help="Comparative to filter by duration")
# TODO Date selector
parser.add(
"--seen",
choices=("seen", "unseen", "any"),