diff --git a/tests/test.py b/tests/test.py index 9aff93d..f69f3d4 100644 --- a/tests/test.py +++ b/tests/test.py @@ -284,7 +284,8 @@ class TestYTMusic(unittest.TestCase): def test_get_charts(self): charts = self.yt_oauth.get_charts() - self.assertEqual(len(charts), 4) + # songs section appears to be removed currently (US) + self.assertGreaterEqual(len(charts), 3) charts = self.yt.get_charts(country="US") self.assertEqual(len(charts), 5) charts = self.yt.get_charts(country="BE") diff --git a/ytmusicapi/mixins/explore.py b/ytmusicapi/mixins/explore.py index 8690af7..9b554ef 100644 --- a/ytmusicapi/mixins/explore.py +++ b/ytmusicapi/mixins/explore.py @@ -95,7 +95,7 @@ class ExploreMixin: Global charts have no Trending section, US charts have an extra Genres section with some Genre charts. :param country: ISO 3166-1 Alpha-2 country code. Default: ZZ = Global - :return: Dictionary containing chart songs (only if authenticated), chart videos, chart artists and + :return: Dictionary containing chart songs (only if authenticated and available), chart videos, chart artists and trending videos. Example:: @@ -209,9 +209,13 @@ class ExploreMixin: ])) charts_categories = ['videos', 'artists'] - has_songs = bool(self.auth) has_genres = country == 'US' has_trending = country != 'ZZ' + # songs section appears to no longer exist, extra length check avoids + # index errors and will still include songs if the feature is added back + has_songs = bool( + self.auth) and len(results) - 1 > (len(charts_categories) + has_genres + has_trending) + if has_songs: charts_categories.insert(0, 'songs') if has_genres: