|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
|
|
from pony import orm # TODO remove
|
|
|
|
|
import requests
|
|
|
|
|
from rss_parser import Parser
|
|
|
|
|
from rss_parser.models import RSSFeed
|
|
|
|
|
from rss_parser.models.rss import RSS
|
|
|
|
|
|
|
|
|
|
from ...models import MediaCollection
|
|
|
|
|
from ..generic import (
|
|
|
|
@ -15,7 +15,7 @@ from ..generic import (
|
|
|
|
|
from .base import CollectionExtractor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RssCollectionExtractor(CollectionExtractor[RSSFeed]):
|
|
|
|
|
class RssCollectionExtractor(CollectionExtractor[RSS]):
|
|
|
|
|
PROTOCOL_PREFIX = "rss+"
|
|
|
|
|
SUPPORTED_PROTOCOLS = [
|
|
|
|
|
"http://",
|
|
|
|
@ -47,20 +47,20 @@ class RssCollectionExtractor(CollectionExtractor[RSSFeed]):
|
|
|
|
|
def can_extract_offline(self, uri: str) -> bool:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def _extract_offline(self, uri: str) -> ExtractedDataOffline[RSSFeed]:
|
|
|
|
|
def _extract_offline(self, uri: str) -> ExtractedDataOffline[RSS]:
|
|
|
|
|
cuted = self.__get_uri(uri)
|
|
|
|
|
return ExtractedDataOffline[RSSFeed](
|
|
|
|
|
return ExtractedDataOffline[RSS](
|
|
|
|
|
extractor_name=self.name,
|
|
|
|
|
object_key=cuted,
|
|
|
|
|
object_uri=uri,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _extract_online(self, uri: str) -> ExtractedDataOnline[RSSFeed]:
|
|
|
|
|
def _extract_online(self, uri: str) -> ExtractedDataOnline[RSS]:
|
|
|
|
|
cuted = self.__get_uri(uri)
|
|
|
|
|
res = requests.get(cuted)
|
|
|
|
|
parser = Parser(xml=res.content)
|
|
|
|
|
data = parser.parse()
|
|
|
|
|
return ExtractedDataOnline[RSSFeed](
|
|
|
|
|
parser = Parser()
|
|
|
|
|
data = parser.parse(data=res.text)
|
|
|
|
|
return ExtractedDataOnline[RSS](
|
|
|
|
|
extractor_name=self.name,
|
|
|
|
|
object_key=cuted,
|
|
|
|
|
object_uri=uri,
|
|
|
|
@ -70,18 +70,18 @@ class RssCollectionExtractor(CollectionExtractor[RSSFeed]):
|
|
|
|
|
def _update_object_raw(
|
|
|
|
|
self,
|
|
|
|
|
object: MediaCollection,
|
|
|
|
|
data: RSSFeed,
|
|
|
|
|
data: RSS,
|
|
|
|
|
) -> ChangedReport:
|
|
|
|
|
object.title = f"[rss] {data.title.strip()}"
|
|
|
|
|
object.description = data.description
|
|
|
|
|
object.title = f"[rss] {data.channel.title.content.strip()}"
|
|
|
|
|
object.description = data.channel.description.content
|
|
|
|
|
object.set_watch_in_order_auto(True)
|
|
|
|
|
object.add_single_uri(
|
|
|
|
|
self.__get_uri(object.primary_uri)
|
|
|
|
|
) # add url without prefix if required
|
|
|
|
|
for item in data.feed:
|
|
|
|
|
for item in data.channel.items:
|
|
|
|
|
element = self._add_episode(
|
|
|
|
|
collection=object,
|
|
|
|
|
uri=item.link,
|
|
|
|
|
uri=item.link.content,
|
|
|
|
|
)
|
|
|
|
|
if element:
|
|
|
|
|
orm.commit()
|
|
|
|
|