This commit is contained in:
Marc Beninca 2025-03-16 22:30:37 +01:00
parent 9e37e3be95
commit 1f046e4ba9
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
2 changed files with 52 additions and 25 deletions

View file

@ -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)

24
rwx/web/__init__.py Normal file
View file

@ -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"""\
<!DOCTYPE html>
<html>
<head>
<meta charset="{self.charset}">
<meta name="description" content="{self.description}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{self.title}</title>
</head>
<body>
</body>
</html>
"""