Fix search edge case for song results with no duration
This commit is contained in:
parent
7cc054899e
commit
a45e872d16
2 changed files with 9 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from typing import List, Dict
|
||||
from .utils import *
|
||||
from ytmusicapi.helpers import i18n
|
||||
|
|
@ -37,7 +38,8 @@ class Parser:
|
|||
runs = get_flex_column_item(data, 1)['text']['runs']
|
||||
last_artist_index = get_last_artist_index(runs)
|
||||
|
||||
if not search_result['videoId'] and default_offset: # unavailable song in default search edge case
|
||||
# unavailable song in default search
|
||||
if not search_result['videoId'] and default_offset:
|
||||
default_offset = 0
|
||||
|
||||
search_result['artists'] = parse_song_artists_runs(
|
||||
|
|
@ -66,7 +68,8 @@ class Parser:
|
|||
|
||||
elif resultType in ['song']:
|
||||
search_result['album'] = parse_song_album_runs(runs, last_artist_index)
|
||||
search_result['duration'] = runs[-1]['text']
|
||||
search_result['duration'] = None if not re.match(
|
||||
r"^\d+:\d+$", runs[-1]['text']) else runs[-1]['text']
|
||||
search_result['isExplicit'] = nav(data, BADGE_LABEL, True) == 'Explicit'
|
||||
if 'menu' in data:
|
||||
toggle_menu = find_object_by_key(nav(data, MENU_ITEMS),
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ def get_last_artist_index(runs):
|
|||
return next(
|
||||
len(runs) - i - 1 for i, run in enumerate(reversed(runs))
|
||||
if 'navigationEndpoint' in run and
|
||||
(nav(run, NAVIGATION_BROWSE_ID).startswith('UC') or
|
||||
nav(run, NAVIGATION_BROWSE_ID).startswith('FEmusic_library_privately_owned_artist')))
|
||||
(nav(run, NAVIGATION_BROWSE_ID).startswith('UC') or nav(
|
||||
run, NAVIGATION_BROWSE_ID).startswith('FEmusic_library_privately_owned_artist')))
|
||||
except StopIteration: # try to find album if no artist IDs available
|
||||
if 'navigationEndpoint' in runs[-3] or runs[-3]['text'].endswith('views'): # has album
|
||||
return len(runs) - 5
|
||||
|
|
@ -45,7 +45,8 @@ def parse_song_album(data, index):
|
|||
|
||||
|
||||
def parse_song_album_runs(runs, last_artist_index):
|
||||
if len(runs) - last_artist_index == 5: # has album
|
||||
if len(runs) > last_artist_index + 1 and type(
|
||||
runs[last_artist_index + 2]) is dict: # has album
|
||||
return {
|
||||
'name': runs[last_artist_index + 2]['text'],
|
||||
'id': nav(runs[last_artist_index + 2], NAVIGATION_BROWSE_ID, True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue