From 55db498b744ae13cef879f481f7fb25229cd1a98 Mon Sep 17 00:00:00 2001 From: Austin Date: Sat, 13 Jan 2024 13:42:15 -0800 Subject: [PATCH 1/4] Remove offset + fix top result Remove offset + fix top result --- ytmusicapi/parsers/search.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index 8011ec8a..da67d90c 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -34,8 +34,13 @@ def parse_top_result(data, search_result_types): search_result["videoType"] = nav(on_tap, NAVIGATION_VIDEO_TYPE) if result_type in ["song", "video", "album"]: + on_tap = data.get("onTap") + if on_tap: + search_result["videoId"] = nav(on_tap, WATCH_VIDEO_ID) + search_result["videoType"] = nav(on_tap, NAVIGATION_VIDEO_TYPE) + search_result["title"] = nav(data, TITLE_TEXT) - runs = nav(data, ["subtitle", "runs"])[2:] + runs = nav(data, ["subtitle", "runs"]) song_info = parse_song_runs(runs) search_result.update(song_info) @@ -125,7 +130,7 @@ def parse_search_result(data, search_result_types, result_type, category): search_result["duration"] = None search_result["year"] = None flex_item = get_flex_column_item(data, 1) - runs = flex_item["text"]["runs"][default_offset:] + runs = flex_item["text"]["runs"] song_info = parse_song_runs(runs) search_result.update(song_info) From 91254ce5e248ba7170d28b46166ec20d72b83c19 Mon Sep 17 00:00:00 2001 From: Austin Date: Sat, 13 Jan 2024 14:49:23 -0800 Subject: [PATCH 2/4] add Null checks add Null checks --- ytmusicapi/parsers/search.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index da67d90c..de3dff3c 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -35,9 +35,13 @@ def parse_top_result(data, search_result_types): if result_type in ["song", "video", "album"]: on_tap = data.get("onTap") - if on_tap: - search_result["videoId"] = nav(on_tap, WATCH_VIDEO_ID) - search_result["videoType"] = nav(on_tap, NAVIGATION_VIDEO_TYPE) + if on_tap is not None: + if "watchEndpoint" in on_tap: + if nav(on_tap, WATCH_VIDEO_ID) is not None: + search_result["videoId"] = nav(on_tap, WATCH_VIDEO_ID) + if "navigationEndpoint" in on_tap: + if nav(on_tap, NAVIGATION_VIDEO_TYPE) is not None: + search_result["videoType"] = nav(on_tap, NAVIGATION_VIDEO_TYPE) search_result["title"] = nav(data, TITLE_TEXT) runs = nav(data, ["subtitle", "runs"]) From 1efef81128ae89f48cdf258e368471c6b9c0b016 Mon Sep 17 00:00:00 2001 From: Austin Date: Sun, 14 Jan 2024 08:10:05 -0800 Subject: [PATCH 3/4] Make updates per comments Make updates per comments --- ytmusicapi/parsers/search.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index de3dff3c..e81674d4 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -35,13 +35,8 @@ def parse_top_result(data, search_result_types): if result_type in ["song", "video", "album"]: on_tap = data.get("onTap") - if on_tap is not None: - if "watchEndpoint" in on_tap: - if nav(on_tap, WATCH_VIDEO_ID) is not None: - search_result["videoId"] = nav(on_tap, WATCH_VIDEO_ID) - if "navigationEndpoint" in on_tap: - if nav(on_tap, NAVIGATION_VIDEO_TYPE) is not None: - search_result["videoType"] = nav(on_tap, NAVIGATION_VIDEO_TYPE) + search_result["videoId"] = nav(data, ["onTap"] + WATCH_VIDEO_ID, True) + search_result["videoType"] = nav(data, ["onTap"] + NAVIGATION_VIDEO_TYPE, True) search_result["title"] = nav(data, TITLE_TEXT) runs = nav(data, ["subtitle", "runs"]) From 62bafe1830a287e2c036dfebef076f314d3ca83f Mon Sep 17 00:00:00 2001 From: sigma67 <16363825+sigma67@users.noreply.github.com> Date: Sun, 14 Jan 2024 19:02:30 +0100 Subject: [PATCH 4/4] Update ytmusicapi/parsers/search.py --- ytmusicapi/parsers/search.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index e81674d4..e64e9b53 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -34,7 +34,6 @@ def parse_top_result(data, search_result_types): search_result["videoType"] = nav(on_tap, NAVIGATION_VIDEO_TYPE) if result_type in ["song", "video", "album"]: - on_tap = data.get("onTap") search_result["videoId"] = nav(data, ["onTap"] + WATCH_VIDEO_ID, True) search_result["videoType"] = nav(data, ["onTap"] + NAVIGATION_VIDEO_TYPE, True)