rssVideos: Show creator
Even if it's not always present for all RSS feeds
This commit is contained in:
parent
9493edc1fd
commit
6a6f5401e6
|
@ -48,38 +48,55 @@ class RVCommand(enum.Enum):
|
||||||
|
|
||||||
|
|
||||||
class RVElement:
|
class RVElement:
|
||||||
title: str
|
|
||||||
link: str
|
|
||||||
# creator: str
|
|
||||||
# description: str
|
|
||||||
# date: datetime.datetime
|
|
||||||
guid: int
|
|
||||||
|
|
||||||
parent: "RVDatabase"
|
parent: "RVDatabase"
|
||||||
|
item: minidom.Element
|
||||||
was_downloaded: bool
|
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:
|
|
||||||
nodes = item.getElementsByTagName(tag_name)
|
|
||||||
if len(nodes) != 1:
|
|
||||||
raise RuntimeError(f"Exepected 1 tag `{tag_name}`, got {len(nodes)}.")
|
|
||||||
children = nodes[0].childNodes
|
|
||||||
if len(children) != 1:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Exepected 1 children for tag `{tag_name}`, got {len(children)}."
|
|
||||||
)
|
|
||||||
return children[0].data
|
|
||||||
|
|
||||||
self.title = get_data("title")
|
|
||||||
self.link = get_data("link")
|
|
||||||
# self.creator = get_data("dc:creator")
|
|
||||||
# self.description = get_data("description")
|
|
||||||
# self.date = get_data("pubDate")
|
|
||||||
self.guid = int(get_data("guid"))
|
|
||||||
|
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.item = item
|
||||||
self.was_downloaded = False
|
self.was_downloaded = False
|
||||||
|
|
||||||
|
def get_tag_data(self, tag_name: str) -> str:
|
||||||
|
nodes = self.item.getElementsByTagName(tag_name)
|
||||||
|
if len(nodes) != 1:
|
||||||
|
raise KeyError(f"Exepected 1 tag `{tag_name}`, got {len(nodes)}.")
|
||||||
|
children = nodes[0].childNodes
|
||||||
|
if len(children) != 1:
|
||||||
|
raise KeyError(
|
||||||
|
f"Exepected 1 children for tag `{tag_name}`, got {len(children)}."
|
||||||
|
)
|
||||||
|
return children[0].data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def title(self) -> str:
|
||||||
|
return self.get_tag_data("title")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def link(self) -> str:
|
||||||
|
return self.get_tag_data("link")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def creator(self) -> typing.Optional[str]:
|
||||||
|
try:
|
||||||
|
return self.get_tag_data("dc:creator")
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self) -> str:
|
||||||
|
# TODO Testing
|
||||||
|
return self.get_tag_data("description")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date(self) -> str:
|
||||||
|
# TODO datetime format
|
||||||
|
return self.get_tag_data("pubDate")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def guid(self) -> int:
|
||||||
|
return int(self.get_tag_data("guid"))
|
||||||
|
|
||||||
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"]
|
||||||
|
@ -88,7 +105,7 @@ class RVElement:
|
||||||
self.was_downloaded = True
|
self.was_downloaded = True
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.title} – {self.link}"
|
return f"{self.guid}: {self.creator} – {self.title} – {self.link}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def downloaded(self) -> bool:
|
def downloaded(self) -> bool:
|
||||||
|
@ -204,15 +221,18 @@ class RVDatabase:
|
||||||
if el.guid in cache_els:
|
if el.guid in cache_els:
|
||||||
el.read_cache(cache_els[el.guid])
|
el.read_cache(cache_els[el.guid])
|
||||||
|
|
||||||
|
@functools.cached_property
|
||||||
|
def feed_xml(self) -> minidom.Document:
|
||||||
|
with urllib.request.urlopen(self.args.feed) as request:
|
||||||
|
return minidom.parse(request)
|
||||||
|
|
||||||
def read_feed(self) -> None:
|
def read_feed(self) -> None:
|
||||||
log.info("Fetching RSS feed")
|
log.info("Fetching RSS feed")
|
||||||
self.elements = list()
|
self.elements = list()
|
||||||
with urllib.request.urlopen(self.args.feed) as request:
|
for item in self.feed_xml.getElementsByTagName("item"):
|
||||||
with minidom.parse(request) as xmldoc:
|
element = RVElement(self, item)
|
||||||
for item in xmldoc.getElementsByTagName("item"):
|
self.elements.insert(0, element)
|
||||||
element = RVElement(self, item)
|
log.debug(f"Known: {element}")
|
||||||
self.elements.insert(0, element)
|
|
||||||
log.debug(f"Known: {element}")
|
|
||||||
|
|
||||||
def clean(self) -> None:
|
def clean(self) -> None:
|
||||||
filenames = set()
|
filenames = set()
|
||||||
|
|
Loading…
Reference in a new issue