any
This commit is contained in:
parent
9e37e3be95
commit
1f046e4ba9
2 changed files with 52 additions and 25 deletions
|
@ -14,28 +14,8 @@
|
||||||
# playlist / entries
|
# 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 abc import ABC, abstractmethod
|
||||||
|
from typing import Any
|
||||||
from rwx import Object
|
from rwx import Object
|
||||||
from rwx.log import stream as log
|
from rwx.log import stream as log
|
||||||
from yt_dlp import YoutubeDL
|
from yt_dlp import YoutubeDL
|
||||||
|
@ -57,15 +37,13 @@ class Tab(Object, ABC):
|
||||||
self.url = self.get_url()
|
self.url = self.get_url()
|
||||||
log.info(self.url)
|
log.info(self.url)
|
||||||
|
|
||||||
def extract(self) -> dict:
|
def extract(self) -> dict[str, Any]:
|
||||||
"""Return extracted dict.
|
"""Return extracted dict.
|
||||||
|
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
yt_dl = Tab.yt_dl(self.get_options())
|
yt_dl = Tab.yt_dl(self.get_options())
|
||||||
return yt_dl.extract_info(
|
return yt_dl.extract_info(self.url, download=False)
|
||||||
self.url, download=False
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_options(self) -> dict:
|
def get_options(self) -> dict:
|
||||||
"""Return options for the action.
|
"""Return options for the action.
|
||||||
|
@ -135,9 +113,34 @@ class Video(Tab):
|
||||||
return f"{Tab.URL_ROOT}/watch?v={self.object_id}"
|
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):
|
class Videos(Tab):
|
||||||
def __init__(self, channel_id: str) -> None:
|
def __init__(self, channel_id: str) -> None:
|
||||||
super().__init__(channel_id)
|
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:
|
def get_url(self) -> str:
|
||||||
return f"{Tab.URL_ROOT}/channel/{self.object_id}/videos"
|
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
24
rwx/web/__init__.py
Normal 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>
|
||||||
|
"""
|
Loading…
Add table
Add a link
Reference in a new issue