Skip to content

Commit

Permalink
prevent parsing errors when an uploaded song lacks a duration
Browse files Browse the repository at this point in the history
  • Loading branch information
apastel committed May 9, 2024
1 parent 65ed89b commit c17924b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ytmusicapi/parsers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def get_dot_separator_index(runs):


def parse_duration(duration):
if duration is None:
# duration may be falsy or a single space: ' '
if not duration or not duration.strip():
return duration
mapped_increments = zip([1, 60, 3600], reversed(duration.split(":")))
seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments)
Expand Down
4 changes: 3 additions & 1 deletion ytmusicapi/parsers/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def parse_uploaded_items(results):
title = get_item_text(data, 0)
like = nav(data, MENU_LIKE_STATUS)
thumbnails = nav(data, THUMBNAILS) if "thumbnail" in data else None
duration = get_fixed_column_item(data, 0)["text"]["runs"][0]["text"]
duration = None
if "fixedColumns" in data:
duration = get_fixed_column_item(data, 0)["text"]["runs"][0]["text"]
song = {
"entityId": entityId,
"videoId": videoId,
Expand Down

0 comments on commit c17924b

Please sign in to comment.