Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Deezer tracks that have been replaced with a newer version fail to play #1892

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions music_assistant/providers/deezer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,18 @@ async def get_stream_details(
),
stream_type=StreamType.CUSTOM,
duration=int(song_data["DURATION"]),
data={"url": url, "format": url_details["format"]},
# Due to track replacement, the track ID of the stream may be different from the ID
# that is stored. We need the proper track ID to decrypt the stream, so store it
# separately so we can use it later on.
data={"url": url, "format": url_details["format"], "track_id": song_data["SNG_ID"]},
size=int(song_data[f"FILESIZE_{url_details['format']}"]),
)

async def get_audio_stream(
self, streamdetails: StreamDetails, seek_position: int = 0
) -> AsyncGenerator[bytes, None]:
"""Return the audio stream for the provider item."""
blowfish_key = self.get_blowfish_key(streamdetails.item_id)
blowfish_key = self.get_blowfish_key(streamdetails.data["track_id"])
chunk_index = 0
timeout = ClientTimeout(total=0, connect=30, sock_read=600)
headers = {}
Expand Down
16 changes: 13 additions & 3 deletions music_assistant/providers/deezer/gw_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ async def get_song_data(self, track_id):
async def get_deezer_track_urls(self, track_id):
"""Get the URL for a given track id."""
dz_license = await self._get_license()
song_data = await self.get_song_data(track_id)
track_token = song_data["results"]["TRACK_TOKEN"]

song_results = await self.get_song_data(track_id)

song_data = song_results["results"]
# If the song has been replaced by a newer version, the old track will
# not play anymore. The data for the newer song is contained in a
# "FALLBACK" entry in the song data. So if that is available, use that
# instead so we get the right track token.
if "FALLBACK" in song_data:
song_data = song_data["FALLBACK"]

track_token = song_data["TRACK_TOKEN"]
url_data = {
"license_token": dz_license,
"media": [
Expand All @@ -151,7 +161,7 @@ async def get_deezer_track_urls(self, track_id):
msg = "Received an error from API"
raise DeezerGWError(msg, error)

return result_json["data"][0]["media"][0], song_data["results"]
return result_json["data"][0]["media"][0], song_data

async def log_listen(
self, next_track: str | None = None, last_track: StreamDetails | None = None
Expand Down