From f73667a5d36713c0c48049ac049126a2dd851e60 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 18 Mar 2025 20:22:11 +0100 Subject: [PATCH] wip --- rwx/sw/ytdlp/__init__.py | 65 +++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/rwx/sw/ytdlp/__init__.py b/rwx/sw/ytdlp/__init__.py index b1fbff5..c947c88 100644 --- a/rwx/sw/ytdlp/__init__.py +++ b/rwx/sw/ytdlp/__init__.py @@ -44,35 +44,26 @@ class Channel(Object): self.uploader_id = d["uploader_id"] self.uploader = d["uploader"] # videos - self.videos_ids = [video["id"] for video in reversed(d["entries"])] - # TODO filter members-only + self.videos_ids = [ + entry["id"] + for entry in reversed(d["entries"]) + if entry["availability"] != "subscriber_only" + ] # playlists d = extract_playlists(channel_id) self.playlists_ids = [playlist["id"] for playlist in reversed(d["entries"])] - def add_video(self, d: dict) -> dict: - """Add video extra info.""" - self.video_index += 1 - log.info(f"{self.video_index} ∕ {len(self.videos_ids)}") - self.videos.append(Video(d)) - return d - def load_videos(self) -> None: """Load videos extra info.""" self.videos = [] - # a - #for index, video_id in enumerate(self.videos_ids): - # log.info(f"{index} ∕ {len(self.videos_ids)}") - # self.videos.append(Video(video_id)) - # b - videos_urls = [url_video(video_id) for video_id in self.videos_ids] - y = ytdl( - { - "process_info_hooks": [self.add_video], - "skip_download": True, - }, - ) - y.download(videos_urls) + for index, video_id in enumerate(self.videos_ids): + log.info(f"{index} ∕ {len(self.videos_ids)}") + self.videos.append(Video(video_id)) + + +# TODO Format +# TODO Playlist/basic,extra +# TODO Thumbnail class Video(Object): @@ -85,17 +76,31 @@ class Video(Object): :type d: dict """ self.at = datetime.now().strftime("%Y%m%d%H%M%S") - # title - # description truncated - # duration - # thumbnails - # view_count + # info self.uid = d["id"] - self.fulltitle = d["fulltitle"] - self.duration = d["duration"] + self.title = d["title"] + self.description_cut = d["description"] + self.duration = int(d["duration"]) + # TODO thumbnail from thumbnails + + def load_extra(self): + d = extract_video(self.uid) + # TODO formats + # TODO thumbnail from thumbnails + # TODO compare existing thumbnail + self.description = d["description"] + # TODO channel_id + self.duration = int(d["duration"]) + self.views = int(d["view_count"]) self.categories = d["categories"] self.tags = d["tags"] - self.description = d["description"] + # TODO automatic_captions + # TODO subtitles + self.chapters = d["chapters"] + self.likes = d["like_count"] + # TODO from epoch + self.timestamp = d["timestamp"] + self.fulltitle = d["fulltitle"] # ╭──────────╮