From 6e0fd5e1dbc0acd3f59714c73f504df55602b854 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Tue, 23 Jul 2024 21:32:39 +0200 Subject: [PATCH] get_podcast: fix edge case when first subtitle is missing --- ytmusicapi/navigation.py | 1 + ytmusicapi/parsers/podcasts.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ytmusicapi/navigation.py b/ytmusicapi/navigation.py index c46aade7..7bf89fa3 100644 --- a/ytmusicapi/navigation.py +++ b/ytmusicapi/navigation.py @@ -6,6 +6,7 @@ RUN_TEXT = ["runs", 0, "text"] TAB_CONTENT = ["tabs", 0, "tabRenderer", "content"] TAB_1_CONTENT = ["tabs", 1, "tabRenderer", "content"] +TAB_2_CONTENT = ["tabs", 2, "tabRenderer", "content"] TWO_COLUMN_RENDERER = ["contents", "twoColumnBrowseResultsRenderer"] SINGLE_COLUMN = ["contents", "singleColumnBrowseResultsRenderer"] SINGLE_COLUMN_TAB = SINGLE_COLUMN + TAB_CONTENT diff --git a/ytmusicapi/parsers/podcasts.py b/ytmusicapi/parsers/podcasts.py index 06e1abc7..a709cd24 100644 --- a/ytmusicapi/parsers/podcasts.py +++ b/ytmusicapi/parsers/podcasts.py @@ -2,6 +2,9 @@ from .songs import * +PROGRESS_RENDERER = ["musicPlaybackProgressRenderer"] +DURATION_TEXT = ["durationText", "runs", 1, "text"] + @dataclass class DescriptionElement: @@ -83,8 +86,8 @@ def parse_episode_header(header: dict) -> dict: metadata["date"] = nav(header, [*SUBTITLE2]) metadata["duration"] = nav(header, [*SUBTITLE3], True) if not metadata["duration"]: # progress started - progress_renderer = nav(header, ["progress", "musicPlaybackProgressRenderer"]) - metadata["duration"] = nav(progress_renderer, ["durationText", "runs", 1, "text"], True) + progress_renderer = nav(header, ["progress", *PROGRESS_RENDERER]) + metadata["duration"] = nav(progress_renderer, DURATION_TEXT, True) metadata["progressPercentage"] = nav(progress_renderer, ["playbackProgressPercentage"]) metadata["saved"] = nav(header, ["buttons", 0, *TOGGLED_BUTTON], True) or False @@ -100,12 +103,8 @@ def parse_episode_header(header: dict) -> dict: def parse_episode(data): """Parses a single episode under "Episodes" on a channel page or on a podcast page""" thumbnails = nav(data, THUMBNAILS) - date = None - if len(nav(data, SUBTITLE_RUNS)) == 1: - duration = nav(data, SUBTITLE) - else: - date = nav(data, SUBTITLE) - duration = nav(data, SUBTITLE2, True) + date = nav(data, SUBTITLE, True) + duration = nav(data, ["playbackProgress", *PROGRESS_RENDERER, *DURATION_TEXT], True) title = nav(data, TITLE_TEXT) description = nav(data, DESCRIPTION, True) videoId = nav(data, ["onTap", *WATCH_VIDEO_ID], True)