Skip to content

Commit

Permalink
get_podcast: fix edge case when first subtitle is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Jul 23, 2024
1 parent 8d6dd11 commit 6e0fd5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions ytmusicapi/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions ytmusicapi/parsers/podcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from .songs import *

PROGRESS_RENDERER = ["musicPlaybackProgressRenderer"]
DURATION_TEXT = ["durationText", "runs", 1, "text"]


@dataclass
class DescriptionElement:
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 6e0fd5e

Please sign in to comment.