Implement subscription from RSS feed
This commit is contained in:
parent
4674cc926c
commit
835b9a42a1
11 changed files with 185 additions and 271 deletions
|
|
@ -1,8 +1,54 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
|
||||
from .youtube_objects import ChannelSnippet, SearchResultItem
|
||||
|
||||
@dataclass
|
||||
class ThumbnailInfo:
|
||||
url: str
|
||||
width: int
|
||||
height: int
|
||||
|
||||
@staticmethod
|
||||
def from_dict(info: dict) -> ThumbnailInfo:
|
||||
return ThumbnailInfo(url=info['url'], width=info['width'], height=info['height'])
|
||||
|
||||
|
||||
@dataclass
|
||||
class VideoInfo:
|
||||
video_id: str
|
||||
title: str
|
||||
description: str
|
||||
url: str
|
||||
thumbnail: ThumbnailInfo
|
||||
published: datetime
|
||||
updated: datetime
|
||||
|
||||
@staticmethod
|
||||
def from_dict(info: dict) -> VideoInfo:
|
||||
return VideoInfo(
|
||||
video_id=info['channel_id'],
|
||||
title=info['title'],
|
||||
description=info['description'],
|
||||
url=info['url'],
|
||||
thumbnail=ThumbnailInfo.from_dict(info['thumbnail']),
|
||||
published=datetime.fromisoformat(info['published']),
|
||||
updated=datetime.fromisoformat(info['updated']))
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChannelInfo:
|
||||
channel_id: str
|
||||
title: str
|
||||
url: str
|
||||
|
||||
@staticmethod
|
||||
def from_dict(info: dict) -> ChannelInfo:
|
||||
return ChannelInfo(
|
||||
channel_id=info['channel_id'],
|
||||
title=info['title'],
|
||||
url=info['url'])
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -10,9 +56,8 @@ class SubscriptionInfo:
|
|||
name: str
|
||||
channel_id: str
|
||||
last_update: float
|
||||
channel_info: ChannelSnippet | None = None
|
||||
shorts_list: list[SearchResultItem] = field(default_factory=list)
|
||||
video_list: list[SearchResultItem] = field(default_factory=list)
|
||||
channel_info: ChannelInfo | None = None
|
||||
video_list: list[VideoInfo] = field(default_factory=list)
|
||||
|
||||
@staticmethod
|
||||
def from_dict(info: dict) -> SubscriptionInfo:
|
||||
|
|
@ -21,9 +66,8 @@ class SubscriptionInfo:
|
|||
name=info['name'],
|
||||
channel_id=info['channel_id'],
|
||||
last_update=info['last_update'],
|
||||
channel_info=ChannelSnippet.from_dict(channel_info) if channel_info is not None else None,
|
||||
shorts_list=[SearchResultItem.from_dict(s) for s in info['shorts_list']],
|
||||
video_list=[SearchResultItem.from_dict(s) for s in info['video_list']])
|
||||
channel_info=ChannelInfo.from_dict(channel_info) if channel_info is not None else None,
|
||||
video_list=[VideoInfo.from_dict(s) for s in info['video_list']])
|
||||
|
||||
|
||||
Subscriptions = dict[str, SubscriptionInfo]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue