diff --git a/rwx/sw/yt_dlp/__init__.py b/rwx/sw/yt_dlp/__init__.py index 3e44298..b949bfc 100644 --- a/rwx/sw/yt_dlp/__init__.py +++ b/rwx/sw/yt_dlp/__init__.py @@ -36,20 +36,11 @@ # view_count from abc import ABC, abstractmethod -from enum import Enum from rwx import Object from rwx.log import stream as log from yt_dlp import YoutubeDL -class Action(Enum): - DOWNLOAD_VIDEO = 0 - EXTRACT_PLAYLIST = 1 - EXTRACT_PLAYLISTS = 2 - EXTRACT_VIDEO = 3 - EXTRACT_VIDEOS = 4 - - class Tab(Object, ABC): """YouTube Tab.""" @@ -65,7 +56,9 @@ class Tab(Object, ABC): log.info(self.object_id) self.url = self.get_url() log.info(self.url) - self.info = Tab.yt_dl(self.get_options()).extract_info(self.url, download=False) + self.info = Tab.yt_dl(self.get_options()).extract_info( + self.url, download=False + ) def get_options(self) -> dict: """Return options for the action. @@ -93,18 +86,18 @@ class Tab(Object, ABC): class Playlist(Tab): def __init__(self, playlist_id: str) -> None: - self.playlist_id = playlist_id + super().__init__(playlist_id) def get_url(self) -> str: - return f"{Tab.URL_ROOT}/playlist?list={self.playlist_id}" + return f"{Tab.URL_ROOT}/playlist?list={self.object_id}" class Playlists(Tab): def __init__(self, channel_id: str) -> None: - self.channel_id = channel_id + super().__init__(channel_id) def get_url(self) -> str: - return f"{Tab.URL_ROOT}/channel/{self.channel_id}/playlists" + return f"{Tab.URL_ROOT}/channel/{self.object_id}/playlists" # id @@ -121,7 +114,7 @@ class Playlists(Tab): # fulltitle class Video(Tab): def __init__(self, video_id: str) -> None: - self.video_id = video_id + super().__init__(video_id) def download(self) -> None: Tab.yt_dl( @@ -134,20 +127,12 @@ class Video(Tab): ).download([self.url]) def get_url(self) -> str: - return f"{Tab.URL_ROOT}/watch?v={self.video_id}" + return f"{Tab.URL_ROOT}/watch?v={self.object_id}" class Videos(Tab): def __init__(self, channel_id: str) -> None: - self.channel_id = channel_id + super().__init__(channel_id) def get_url(self) -> str: - return f"{Tab.URL_ROOT}/channel/{self.channel_id}/videos" - - -def command(action: Action): - log.info(options) - with dl(options) as youtube: - match action: - case _: - youtube.extract_info(url, download=False) + return f"{Tab.URL_ROOT}/channel/{self.object_id}/videos"