[GH-ISSUE #161] Search breaks: IndexError: list index out of range #123

Closed
opened 2026-02-27 22:08:09 +03:00 by kerem · 8 comments
Owner

Originally created by @chaos87 on GitHub (Jan 28, 2021).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/161

Hi,

I'm testing version 0.13.1

and when I query 'dinosaur jr'
I'm getting

Traceback (most recent call last):
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask_cors/decorator.py", line 128, in wrapped_function
    resp = make_response(f(*args, **kwargs))
  File "/home/chaos87/noisedge/main.py", line 20, in search_yt_music
    results = get_search_results_from_query(ytmusic, query)
  File "/home/chaos87/noisedge/utils.py", line 17, in get_search_results_from_query
    results = ytdriver.search(query)
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/mixins/browsing.py", line 119, in search
    search_results.extend(self.parser.parse_search_results(results, type))
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/helpers.py", line 83, in _impl
    return method(self, *method_args, **method_kwargs)
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/parsers/browsing.py", line 41, in parse_search_results
    runs[default_offset:last_artist_index + 1])
  File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/parsers/utils.py", line 16, in parse_song_artists_runs
    'name': runs[j * 2]['text'],
IndexError: list index out of range
Originally created by @chaos87 on GitHub (Jan 28, 2021). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/161 Hi, I'm testing version 0.13.1 and when I query 'dinosaur jr' I'm getting ``` Traceback (most recent call last): File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise raise value File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/flask_cors/decorator.py", line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File "/home/chaos87/noisedge/main.py", line 20, in search_yt_music results = get_search_results_from_query(ytmusic, query) File "/home/chaos87/noisedge/utils.py", line 17, in get_search_results_from_query results = ytdriver.search(query) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/mixins/browsing.py", line 119, in search search_results.extend(self.parser.parse_search_results(results, type)) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/helpers.py", line 83, in _impl return method(self, *method_args, **method_kwargs) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/parsers/browsing.py", line 41, in parse_search_results runs[default_offset:last_artist_index + 1]) File "/home/chaos87/noisedge/venv/lib/python3.6/site-packages/ytmusicapi/parsers/utils.py", line 16, in parse_song_artists_runs 'name': runs[j * 2]['text'], IndexError: list index out of range ```
kerem closed this issue 2026-02-27 22:08:09 +03:00
Author
Owner

@sigma67 commented on GitHub (Jan 28, 2021):

I cannot reproduce unfortunately. Can you pinpoint which search result is causing this? Are you using an authenticated instance?

<!-- gh-comment-id:768984906 --> @sigma67 commented on GitHub (Jan 28, 2021): I cannot reproduce unfortunately. Can you pinpoint which search result is causing this? Are you using an authenticated instance?
Author
Owner

@chaos87 commented on GitHub (Jan 28, 2021):

Thanks for the quick reply.
I'm getting the error with this code

from ytmusicapi import YTMusic
ytmusic = YTMusic()
results = ytmusic.search("dinosaur jr")

I'm using an unauthenticated instance

<!-- gh-comment-id:769130022 --> @chaos87 commented on GitHub (Jan 28, 2021): Thanks for the quick reply. I'm getting the error with this code ``` from ytmusicapi import YTMusic ytmusic = YTMusic() results = ytmusic.search("dinosaur jr") ``` I'm using an unauthenticated instance
Author
Owner

@sigma67 commented on GitHub (Jan 28, 2021):

These are my results for that search term, unauthenticated (JSON below). Thumbnails removed for brevity. They might be different from your location. Do you see any unusual songs in your song/video results that don't appear in mine? Unusual would mean that some subtitles are odd or missing. You can check using the web interface if ytmusicapi breaks.

[
  {
    "album": {
      "id": "MPREb_h8SAlsjN1Ss",
      "name": "Live In The Middle East"
    },
    "artists": [
      {
        "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA",
        "name": "Dinosaur Jr."
      }
    ],
    "duration": "3:11",
    "feedbackTokens": {
      "add": null,
      "remove": null
    },
    "isExplicit": false,
    "radioId": "RDAMVMblAvutJz8g0",
    "resultType": "song",
    "title": "Little Fury Things (Live)",
    "videoId": "blAvutJz8g0"
  },
  {
    "album": {
      "id": "MPREb_TiurcWdbLDI",
      "name": "Without a Sound"
    },
    "artists": [
      {
        "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA",
        "name": "Dinosaur Jr."
      }
    ],
    "duration": "4:19",
    "feedbackTokens": {
      "add": null,
      "remove": null
    },
    "isExplicit": false,
    "radioId": "RDAMVMOkkKimuDNIQ",
    "resultType": "song",
    "title": "Feel the Pain",
    "videoId": "OkkKimuDNIQ"
  },
  {
    "album": {
      "id": "MPREb_Ffot3PSS1an",
      "name": "Bug"
    },
    "artists": [
      {
        "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA",
        "name": "Dinosaur Jr."
      }
    ],
    "duration": "3:36",
    "feedbackTokens": {
      "add": null,
      "remove": null
    },
    "isExplicit": false,
    "radioId": "RDAMVMz45yWIXipy8",
    "resultType": "song",
    "title": "Freak Scene",
    "videoId": "z45yWIXipy8"
  },
  {
    "artists": [
      {
        "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA",
        "name": "Dinosaur Jr."
      }
    ],
    "duration": "4:39",
    "radioId": "RDAMVMJXkN3nJyWEA",
    "resultType": "video",
    "title": "Feel the Pain",
    "videoId": "JXkN3nJyWEA",
    "views": "1.8M"
  },
  {
    "artists": [
      {
        "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA",
        "name": "Dinosaur Jr."
      }
    ],
    "duration": "3:46",
    "radioId": "RDAMVMTgTJtdn6VjM",
    "resultType": "video",
    "title": "Over It",
    "videoId": "TgTJtdn6VjM",
    "views": "3M"
  },
  {
    "artists": [
      {
        "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA",
        "name": "Dinosaur Jr."
      }
    ],
    "duration": "3:35",
    "radioId": "RDAMVM5eO6up9Gpv0",
    "resultType": "video",
    "title": "Freak Scene",
    "videoId": "5eO6up9Gpv0",
    "views": "567K"
  }
]
<!-- gh-comment-id:769148614 --> @sigma67 commented on GitHub (Jan 28, 2021): These are my results for that search term, unauthenticated (JSON below). Thumbnails removed for brevity. They might be different from your location. Do you see any unusual songs in your song/video results that don't appear in mine? Unusual would mean that some subtitles are odd or missing. You can check using the web interface if ytmusicapi breaks. ```json [ { "album": { "id": "MPREb_h8SAlsjN1Ss", "name": "Live In The Middle East" }, "artists": [ { "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA", "name": "Dinosaur Jr." } ], "duration": "3:11", "feedbackTokens": { "add": null, "remove": null }, "isExplicit": false, "radioId": "RDAMVMblAvutJz8g0", "resultType": "song", "title": "Little Fury Things (Live)", "videoId": "blAvutJz8g0" }, { "album": { "id": "MPREb_TiurcWdbLDI", "name": "Without a Sound" }, "artists": [ { "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA", "name": "Dinosaur Jr." } ], "duration": "4:19", "feedbackTokens": { "add": null, "remove": null }, "isExplicit": false, "radioId": "RDAMVMOkkKimuDNIQ", "resultType": "song", "title": "Feel the Pain", "videoId": "OkkKimuDNIQ" }, { "album": { "id": "MPREb_Ffot3PSS1an", "name": "Bug" }, "artists": [ { "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA", "name": "Dinosaur Jr." } ], "duration": "3:36", "feedbackTokens": { "add": null, "remove": null }, "isExplicit": false, "radioId": "RDAMVMz45yWIXipy8", "resultType": "song", "title": "Freak Scene", "videoId": "z45yWIXipy8" }, { "artists": [ { "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA", "name": "Dinosaur Jr." } ], "duration": "4:39", "radioId": "RDAMVMJXkN3nJyWEA", "resultType": "video", "title": "Feel the Pain", "videoId": "JXkN3nJyWEA", "views": "1.8M" }, { "artists": [ { "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA", "name": "Dinosaur Jr." } ], "duration": "3:46", "radioId": "RDAMVMTgTJtdn6VjM", "resultType": "video", "title": "Over It", "videoId": "TgTJtdn6VjM", "views": "3M" }, { "artists": [ { "id": "UCIhZQ-Z3wMKtMVJ7k9gc-gA", "name": "Dinosaur Jr." } ], "duration": "3:35", "radioId": "RDAMVM5eO6up9Gpv0", "resultType": "video", "title": "Freak Scene", "videoId": "5eO6up9Gpv0", "views": "567K" } ] ```
Author
Owner

@pushrbx commented on GitHub (Jan 28, 2021):

@sigma67 you can repro the error with https://github.com/sigma67/spotifyplaylist_to_gmusic

python YouTube.py https://open.spotify.com/playlist/0Zalm7sVYUtJMJFo9Vahb1

As an authenticated user.

<!-- gh-comment-id:769258579 --> @pushrbx commented on GitHub (Jan 28, 2021): @sigma67 you can repro the error with https://github.com/sigma67/spotifyplaylist_to_gmusic ``` python YouTube.py https://open.spotify.com/playlist/0Zalm7sVYUtJMJFo9Vahb1 ``` As an authenticated user.
Author
Owner

@sigma67 commented on GitHub (Jan 28, 2021):

So this one's due to an unavailable song which is missing the typical Song •.

@chaos87 can you confirm that there is also an unavailable song in your search result? Just to make sure it's the same issue.

Edit: If it was the same issue, it should no longer crash with latest master.

<!-- gh-comment-id:769279615 --> @sigma67 commented on GitHub (Jan 28, 2021): So this one's due to an unavailable song which is missing the typical `Song •`. @chaos87 can you confirm that there is also an unavailable song in your search result? Just to make sure it's the same issue. Edit: If it was the same issue, it should no longer crash with latest master.
Author
Owner

@chaos87 commented on GitHub (Jan 29, 2021):

I'm not sure what is an unavailable song or how to identify it. By the past I saw songs results with missing videoId, but the search wouldn't break (and also in 0.13.1).

I can include a more detailed traceback, hope that can help

IndexError                                Traceback (most recent call last)
<ipython-input-3-821334cb3c00> in <module>()
      3 from fuzzywuzzy import fuzz
      4 ytmusic = YTMusic()
----> 5 results = ytmusic.search("dinosaur jr")
      6 df_search = pd.DataFrame(results)
      7 # pp.pprint(results)

3 frames
/usr/local/lib/python3.6/dist-packages/ytmusicapi/mixins/browsing.py in search(self, query, filter, limit, ignore_spelling)
    117 
    118                 type = filter[:-1] if filter else None
--> 119                 search_results.extend(self.parser.parse_search_results(results, type))
    120 
    121                 if 'continuations' in res['musicShelfRenderer']:

/usr/local/lib/python3.6/dist-packages/ytmusicapi/helpers.py in _impl(self, *method_args, **method_kwargs)
     81     def _impl(self, *method_args, **method_kwargs):
     82         method.__globals__['_'] = self.lang.gettext
---> 83         return method(self, *method_args, **method_kwargs)
     84 
     85     return _impl

/usr/local/lib/python3.6/dist-packages/ytmusicapi/parsers/browsing.py in parse_search_results(self, results, resultType)
     39 
     40                 search_result['artists'] = parse_song_artists_runs(
---> 41                     runs[default_offset:last_artist_index + 1])
     42 
     43             if resultType in ['artist', 'album', 'playlist']:

/usr/local/lib/python3.6/dist-packages/ytmusicapi/parsers/utils.py in parse_song_artists_runs(runs)
     14     for j in range(int(len(runs) / 2) + 1):
     15         artists.append({
---> 16             'name': runs[j * 2]['text'],
     17             'id': nav(runs[j * 2], NAVIGATION_BROWSE_ID, True)
     18         })

IndexError: list index out of range
<!-- gh-comment-id:769511740 --> @chaos87 commented on GitHub (Jan 29, 2021): I'm not sure what is an unavailable song or how to identify it. By the past I saw songs results with missing videoId, but the search wouldn't break (and also in 0.13.1). I can include a more detailed traceback, hope that can help ```python IndexError Traceback (most recent call last) <ipython-input-3-821334cb3c00> in <module>() 3 from fuzzywuzzy import fuzz 4 ytmusic = YTMusic() ----> 5 results = ytmusic.search("dinosaur jr") 6 df_search = pd.DataFrame(results) 7 # pp.pprint(results) 3 frames /usr/local/lib/python3.6/dist-packages/ytmusicapi/mixins/browsing.py in search(self, query, filter, limit, ignore_spelling) 117 118 type = filter[:-1] if filter else None --> 119 search_results.extend(self.parser.parse_search_results(results, type)) 120 121 if 'continuations' in res['musicShelfRenderer']: /usr/local/lib/python3.6/dist-packages/ytmusicapi/helpers.py in _impl(self, *method_args, **method_kwargs) 81 def _impl(self, *method_args, **method_kwargs): 82 method.__globals__['_'] = self.lang.gettext ---> 83 return method(self, *method_args, **method_kwargs) 84 85 return _impl /usr/local/lib/python3.6/dist-packages/ytmusicapi/parsers/browsing.py in parse_search_results(self, results, resultType) 39 40 search_result['artists'] = parse_song_artists_runs( ---> 41 runs[default_offset:last_artist_index + 1]) 42 43 if resultType in ['artist', 'album', 'playlist']: /usr/local/lib/python3.6/dist-packages/ytmusicapi/parsers/utils.py in parse_song_artists_runs(runs) 14 for j in range(int(len(runs) / 2) + 1): 15 artists.append({ ---> 16 'name': runs[j * 2]['text'], 17 'id': nav(runs[j * 2], NAVIGATION_BROWSE_ID, True) 18 }) IndexError: list index out of range ```
Author
Owner

@sigma67 commented on GitHub (Jan 29, 2021):

At this point it would be most helpful if you could update to master using pip install -U git+https://github.com/sigma67/ytmusicapi and check if that fixes the issue.

By the past I saw songs results with missing videoId, but the search wouldn't break (and also in 0.13.1).

Those would be the unavailable ones. I think it's breaking again now because of some other bugfixes made in the meantime, but might also be a YouTube update

<!-- gh-comment-id:769694364 --> @sigma67 commented on GitHub (Jan 29, 2021): At this point it would be most helpful if you could update to master using `pip install -U git+https://github.com/sigma67/ytmusicapi` and check if that fixes the issue. > By the past I saw songs results with missing videoId, but the search wouldn't break (and also in 0.13.1). Those would be the unavailable ones. I think it's breaking again now because of some other bugfixes made in the meantime, but might also be a YouTube update
Author
Owner

@chaos87 commented on GitHub (Jan 29, 2021):

@sigma67 I just tried and yes it solves the issue! Thanks

<!-- gh-comment-id:769812493 --> @chaos87 commented on GitHub (Jan 29, 2021): @sigma67 I just tried and yes it solves the issue! Thanks
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#123
No description provided.