From 1f046e4ba94b9e1aeb653d580418192d0112e294 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 16 Mar 2025 22:30:37 +0100 Subject: [PATCH] any --- rwx/sw/yt_dlp/__init__.py | 53 +++++++++++++++++++++------------------ rwx/web/__init__.py | 24 ++++++++++++++++++ 2 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 rwx/web/__init__.py diff --git a/rwx/sw/yt_dlp/__init__.py b/rwx/sw/yt_dlp/__init__.py index f8db074..9e261ff 100644 --- a/rwx/sw/yt_dlp/__init__.py +++ b/rwx/sw/yt_dlp/__init__.py @@ -14,28 +14,8 @@ # playlist / entries # … -# videos -# id -# channel -# channel_id -# title -# channel_follower_count -# description -# tags -# thumbnails -# uploader_id -# uploader -# entries - -# videos / entries -# id -# title -# description truncated -# duration -# thumbnails -# view_count - from abc import ABC, abstractmethod +from typing import Any from rwx import Object from rwx.log import stream as log from yt_dlp import YoutubeDL @@ -57,15 +37,13 @@ class Tab(Object, ABC): self.url = self.get_url() log.info(self.url) - def extract(self) -> dict: + def extract(self) -> dict[str, Any]: """Return extracted dict. :rtype: dict """ yt_dl = Tab.yt_dl(self.get_options()) - return yt_dl.extract_info( - self.url, download=False - ) + return yt_dl.extract_info(self.url, download=False) def get_options(self) -> dict: """Return options for the action. @@ -135,9 +113,34 @@ class Video(Tab): return f"{Tab.URL_ROOT}/watch?v={self.object_id}" +# channel +# title +# channel_follower_count +# description +# tags +# thumbnails +# uploader_id +# uploader +# videos / entries +# title +# description truncated +# duration +# thumbnails +# view_count class Videos(Tab): def __init__(self, channel_id: str) -> None: super().__init__(channel_id) + info = self.extract() + self.title = info["title"] + self.ids = [v["id"] for v in info["entries"]] + self.videos = {} def get_url(self) -> str: return f"{Tab.URL_ROOT}/channel/{self.object_id}/videos" + + def load(self) -> None: + done = 0 + for video_id in self.ids: + self.videos[video_id] = Video(video_id) + done += 1 + log.info(done) diff --git a/rwx/web/__init__.py b/rwx/web/__init__.py new file mode 100644 index 0000000..943a3f4 --- /dev/null +++ b/rwx/web/__init__.py @@ -0,0 +1,24 @@ +from rwx import Object, txt +from rwx.txt import CHARSET + + +class Page(Object): + def __init__(self): + self.charset = CHARSET + self.description = "" + self.title = "" + + def render(self) -> str: + return f"""\ + + + + + + +{self.title} + + + + +"""