rssVideos: Replace guid by date and id
This commit is contained in:
parent
c36534f696
commit
8ae5c00f53
|
@ -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).
|
with the unread items (non-video links are ignored).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -26,7 +27,6 @@ import yt_dlp
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
# TODO Lockfile, or a way to parallel watch and download
|
# 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:
|
def configure_logging(args: configargparse.Namespace) -> None:
|
||||||
|
@ -131,8 +131,8 @@ class RVElement:
|
||||||
return self.item["origin"]["title"]
|
return self.item["origin"]["title"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def guid(self) -> int:
|
def date(self) -> datetime.datetime:
|
||||||
return int(self.item["timestampUsec"])
|
return datetime.datetime.fromtimestamp(self.item["published"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_researched(self) -> bool:
|
def is_researched(self) -> bool:
|
||||||
|
@ -146,16 +146,19 @@ class RVElement:
|
||||||
self.downloaded_filepath = cache.downloaded_filepath
|
self.downloaded_filepath = cache.downloaded_filepath
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
# return self.item.get("id")
|
str = f"{self.date.strftime('%y-%m-%d %H:%M')} ("
|
||||||
str = f"{self.guid}: {self.creator if self.creator else '?'} – {self.title}"
|
|
||||||
if self.is_researched:
|
if self.is_researched:
|
||||||
if self.is_video:
|
if self.is_video:
|
||||||
str += f" ({format_duration(self.duration)})"
|
str += format_duration(self.duration)
|
||||||
else:
|
else:
|
||||||
str += " (N/A)"
|
str += "--:--:--"
|
||||||
else:
|
else:
|
||||||
str += " (?)"
|
str += "??:??:??"
|
||||||
str += f" – {self.link}"
|
str += (
|
||||||
|
f") {self.creator if self.creator else '?'} "
|
||||||
|
f"– {self.title} "
|
||||||
|
f"– {self.link}"
|
||||||
|
)
|
||||||
return str
|
return str
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -247,9 +250,6 @@ class RVElement:
|
||||||
if args.title and not re.search(args.title, self.title):
|
if args.title and not re.search(args.title, self.title):
|
||||||
log.debug(f"Title not matching {args.title}: {self}")
|
log.debug(f"Title not matching {args.title}: {self}")
|
||||||
return False
|
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):
|
if args.link and not re.search(args.link, self.link):
|
||||||
log.debug(f"Link not matching {args.link}: {self}")
|
log.debug(f"Link not matching {args.link}: {self}")
|
||||||
return False
|
return False
|
||||||
|
@ -353,18 +353,18 @@ class RVDatabase:
|
||||||
log.debug("Salvaging cache")
|
log.debug("Salvaging cache")
|
||||||
cache_els = dict()
|
cache_els = dict()
|
||||||
for cache_el in cache.elements:
|
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:
|
for el in self.elements:
|
||||||
if el.guid in cache_els:
|
if el.id in cache_els:
|
||||||
el.salvage_cache(cache_els[el.guid])
|
el.salvage_cache(cache_els[el.id])
|
||||||
|
|
||||||
def clean_cache(self, cache: "RVDatabase") -> None:
|
def clean_cache(self, cache: "RVDatabase") -> None:
|
||||||
log.debug("Cleaning cache")
|
log.debug("Cleaning cache")
|
||||||
self_els = dict()
|
self_els = dict()
|
||||||
for self_el in self.elements:
|
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:
|
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:
|
if el.is_researched and el.is_video:
|
||||||
el.clean()
|
el.clean()
|
||||||
|
|
||||||
|
@ -600,11 +600,11 @@ def get_args() -> configargparse.Namespace:
|
||||||
default="old",
|
default="old",
|
||||||
help="Sorting mechanism",
|
help="Sorting mechanism",
|
||||||
)
|
)
|
||||||
parser.add("--guid", help="Regex to filter guid")
|
|
||||||
parser.add("--creator", help="Regex to filter by creator")
|
parser.add("--creator", help="Regex to filter by creator")
|
||||||
parser.add("--title", help="Regex to filter by title")
|
parser.add("--title", help="Regex to filter by title")
|
||||||
parser.add("--link", help="Regex to filter by link")
|
parser.add("--link", help="Regex to filter by link")
|
||||||
parser.add("--duration", help="Comparative to filter by duration")
|
parser.add("--duration", help="Comparative to filter by duration")
|
||||||
|
# TODO Date selector
|
||||||
parser.add(
|
parser.add(
|
||||||
"--seen",
|
"--seen",
|
||||||
choices=("seen", "unseen", "any"),
|
choices=("seen", "unseen", "any"),
|
||||||
|
|
Loading…
Reference in a new issue