Skip to content

Commit

Permalink
get_podcast, get_episode: improve edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Jan 22, 2024
1 parent be7a609 commit 47b27f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 12 additions & 0 deletions tests/mixins/test_podcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def test_get_podcast(self, yt, yt_brand):
assert len(results["episodes"]) > 100
assert results["saved"]

def test_many_podcasts(self, yt):
results = yt.search("podcast", filter="podcasts")
for result in results:
results = yt.get_podcast(result["browseId"])
assert len(results) > 0

def test_get_episode(self, yt, yt_brand):
podcast_id = "KNkyHCLOr1o" # 124. Making Meetings Meaningful, Pt. 1: How to Structure
result = yt.get_episode(podcast_id)
Expand All @@ -19,3 +25,9 @@ def test_get_episode(self, yt, yt_brand):

result = yt_brand.get_episode(podcast_id)
assert result["saved"]

def test_many_episodes(self, yt):
results = yt.search("episode", filter="episodes")
for result in results:
result = yt.get_episode(result["videoId"])
assert len(result["description"].text) > 0
11 changes: 7 additions & 4 deletions ytmusicapi/parsers/podcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _parse_base_header(header: Dict) -> Dict:

def parse_podcast_header(header: Dict) -> Dict:
metadata = _parse_base_header(header)
metadata["description"] = nav(header, ["description", *DESCRIPTION_SHELF, *DESCRIPTION])
metadata["description"] = nav(header, ["description", *DESCRIPTION_SHELF, *DESCRIPTION], True)
metadata["saved"] = nav(header, ["buttons", 1, *TOGGLED_BUTTON])

return metadata
Expand All @@ -103,10 +103,13 @@ def parse_episodes(results) -> List[Dict]:
episodes = []
for result in results:
data = nav(result, ["musicMultiRowListItemRenderer"])
date = nav(data, SUBTITLE)
duration = nav(data, SUBTITLE2)
if len(nav(data, SUBTITLE_RUNS)) == 1:
duration = nav(data, SUBTITLE)
else:
date = nav(data, SUBTITLE)
duration = nav(data, SUBTITLE2, True)
title = nav(data, TITLE_TEXT)
description = nav(data, DESCRIPTION)
description = nav(data, DESCRIPTION, True)
videoId = nav(data, ["onTap", *WATCH_VIDEO_ID], True)
browseId = nav(data, [*TITLE, *NAVIGATION_BROWSE_ID], True)
videoType = nav(data, ["onTap", *NAVIGATION_VIDEO_TYPE], True)
Expand Down

0 comments on commit 47b27f0

Please sign in to comment.