sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.71k stars 194 forks source link

KeyError: 'musicResponsiveListItemRenderer' When Calling get_charts with Non-Global Country Codes #551

Closed PelicanSL closed 7 months ago

PelicanSL commented 7 months ago

Description When using the get_charts method from ytmusicapi, specifying the global country code "ZZ" works as expected and returns chart data without issues. However, attempting to use any other country code (e.g., "ES", "US", "FR", "EN") results in a KeyError for 'musicResponsiveListItemRenderer'. This issue occurs across different country codes, suggesting a problem with handling responses for specific countries other than the global charts.

To Reproduce: Steps to reproduce the behavior:

  1. Initialize YTMusic object.
  2. Call get_charts method with a country code other than "ZZ", e.g., yt.get_charts("ES").
  3. Observe the KeyError: 'musicResponsiveListItemRenderer'.

Expected Behavior: The expected behavior is for the get_charts method to return chart data for the specified country without raising an error, similar to how it behaves with the global country code "ZZ".

Actual Behavior: A KeyError is raised for 'musicResponsiveListItemRenderer', indicating a failure to parse the API response for non-global country codes.

Error Message:

Captura de pantalla 2024-02-21 a las 20 22 14

Additional Context:

Code Sample:

from ytmusicapi import YTMusic

yt = YTMusic()
country = "ES"  # Example country code distinct from ZZ
search_results = yt.get_charts(country)
print(search_results) 

I have the library updated to version 1.5.2, and the issue persists across various non-global country codes, indicating a broader problem with handling country-specific chart data.

Thanks!!

sigma67 commented 7 months ago

This is hard to debug without the actual JSON data being returned for you. You can retrieve it via the POST requests when navigating to the charts page on YouTube Music.

Screenshots may help as well.

I know YouTube Music has been doing A/B tests lately on that page because I've been affected as well (the Trending category stopped showing up for a while, but now it's back).

fischcode commented 7 months ago

I can confirm this issue with ytmusicapi 1.5.2.; As the issue does not appear in branch fix-548 it appears to have been caused by the modifications in ytmusic 1.5.2 which have been reverted in that branch.

sigma67 commented 7 months ago

@PelicanSL can you check with 1.5.3 and close if fixed?