Skip to content

fix: adapt to Shazam API endpoint changes#148

Open
alejandromav wants to merge 1 commit intoshazamio:masterfrom
alejandromav:fix-shazam-api-endpoints
Open

fix: adapt to Shazam API endpoint changes#148
alejandromav wants to merge 1 commit intoshazamio:masterfrom
alejandromav:fix-shazam-api-endpoints

Conversation

@alejandromav
Copy link
Copy Markdown

@alejandromav alejandromav commented Feb 13, 2026

Summary

Several Shazam API endpoints have been deprecated or shut down, causing FailedDecodeJson / HTTP 404 / 405 errors across multiple library methods. This PR migrates to the replacement endpoints that are still functional.

Fixes #145, fixes #146, fixes #147

What changed

Search (search_track, search_artist)

  • The old services/search/v3/... endpoints now return 404.
  • Migrated to the Apple Music catalog search API: amapi/v1/catalog/{country}/search?term={query}&types={songs|artists}.

Charts (top_world_tracks, top_country_tracks, top_city_tracks, top_world_genre_tracks, top_country_genre_tracks)

  • The old JSON playlist/chart endpoints no longer return valid data.
  • Migrated to Shazam's CSV chart endpoints (https://www.shazam.com/services/charts/csv/...), which return ranked track lists.
  • Added validate_csv utility to parse CSV responses and request_csv to the HTTP client.
  • Updated GeoService (converter) with helper methods to resolve URL-friendly location/genre names for the new chart URLs.

Artist lookup (artist_about)

  • The direct amapi/v1/catalog/{country}/artists/{id} endpoint was shut down.
  • Now resolves the artist name by scraping the public Shazam artist page (shazam.com/artist/_/{id}), then searches via the catalog search API.
  • Added optional artist_name parameter to skip the resolution step when the name is already known.
  • Made ArtistV3.views optional to accommodate the new response shape from the search API.

Deprecated methods

  • listening_counter, listening_counter_many, artist_albums, and search_album are marked @deprecated — their underlying endpoints are no longer available and have no known replacements.

Files changed

File Change
shazamio/api.py Rewired search, chart, and artist methods to new endpoints; added _resolve_artist_name; deprecated dead methods
shazamio/misc.py Added SEARCH_AMAPI and CHART_CSV URL constants; removed broken URLs
shazamio/utils.py Added validate_csv for parsing chart CSV responses
shazamio/client.py Added request_csv method
shazamio/interfaces/client.py Added request_csv to the HTTP client interface
shazamio/converter.py Added URL-name resolvers for countries, cities, and genres
shazamio/schemas/artists.py Made ArtistV3.views optional
tests/test_about_artist.py Added test_about_artist_by_name
tests/test_search.py New: test_search_track, test_search_artist
tests/test_charts.py New: tests for all five chart methods
tests/test_track_about.py New: test_track_about
tests/test_related_tracks.py New: test_related_tracks

Test plan

  • All 17 original tests pass without modification
  • 1 new test added to existing test_about_artist.py
  • 4 new test files with 10 additional tests (search, charts, track info, related tracks)
  • black --check . passes (pre-existing factory_misc.py issue excluded)
  • Full suite: 18 passed via pytest -v

Notes

  • The CSV chart endpoints return less data than the old JSON ones (rank, title, subtitle only). The response dict structure ({"tracks": [...]}) is preserved for backward compatibility, but individual track dicts are simpler.
  • The artist_about method now makes an extra HTTP call to resolve the artist name from the Shazam web page when called with artist_id. Pass artist_name directly to avoid this overhead.
  • Methods marked @deprecated still exist but raise a DeprecationWarning and return an error dict explaining the endpoint is no longer available.

…hazamio#147)

- Search: use amapi/v1/catalog/search for search_track and search_artist
- Charts: use CSV chart endpoints for top_world/country/city/genre_tracks
- artist_about: resolve artist name from Shazam page when using artist_id,
  then search via catalog search; support artist_name for direct lookup
- Add request_csv and validate_csv for chart CSV responses
- Mark listening_counter, listening_counter_many, artist_albums, search_album
  as deprecated (endpoints no longer available)
- Make ArtistV3.views optional for new response shape
- Add tests for search, charts, track_about, related_tracks, artist_by_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant