Skip to content

feat: add FLAC lossless format support#316

Merged
kokarare1212 merged 2 commits intokokarare1212:mainfrom
akbad:feat/add-flac
Oct 11, 2025
Merged

feat: add FLAC lossless format support#316
kokarare1212 merged 2 commits intokokarare1212:mainfrom
akbad:feat/add-flac

Conversation

@akbad
Copy link
Copy Markdown
Contributor

@akbad akbad commented Oct 11, 2025

Summary

  • Adds FLAC lossless audio format support to librespot-python based on format codes in librespot upstream
  • Refactors quality picker classes for DRYness while maintaining backward compatibility

Details

  • Add FLAC_FLAC (16) and FLAC_FLAC_24BIT (22) format codes to metadata.proto

  • Add enum values for FLAC:

    • SuperAudioFormat.FLAC maps FLAC formats to FLAC container type
    • AudioQuality.LOSSLESS maps FLAC formats to lossless quality tier
  • Refactor to generic DRY FormatOnlyAudioQuality base class, while maintaining 100% backward compatibility via:

    • Maintaining existing VorbisOnlyAudioQuality as a wrapper
    • Adding new LosslessOnlyAudioQuality wrapper for FLAC file selection
  • Also fixes minor bug within unknown-format error in decoders.py

akbad added 2 commits October 10, 2025 19:48
- Bug existed since #8
- Resurfaced while adding FLAC
…while staying backward compatible)

- Add `FLAC_FLAC` (16), `FLAC_FLAC_24BIT` (22) format codes (based on librespot-org/librespot#796, librespot-org/librespot#1424)
- Regenerate Metadata_pb2.py with protoc 3.20.1
- Add enums: `SuperAudioFormat.FLAC`, `AudioQuality.LOSSLESS`
- Refactor to generic DRY `FormatOnlyAudioQuality` base class while maintaining existing `VorbisOnlyAudioQuality` as wrapper
- Remove `AAC_24_NORM` (replaced by `FLAC_FLAC` at code 16)
@akbad
Copy link
Copy Markdown
Contributor Author

akbad commented Oct 11, 2025

Please note the failed DeepSource Python check stems from me reusing the existing way of formatting strings for the logger within my changes. Let me know if this is something I should update.

@kokarare1212 kokarare1212 marked this pull request as ready for review October 11, 2025 00:57
@kokarare1212 kokarare1212 merged commit a96b11c into kokarare1212:main Oct 11, 2025
3 of 4 checks passed
@kokarare1212
Copy link
Copy Markdown
Owner

Thanks for the PR!
It looks great!

@Googolplexed0
Copy link
Copy Markdown
Contributor

@akbad I've implemented this lossless format in a downstream project, but I'm having no luck getting FLAC files (even with songs that the mainline app claims to have lossless versions of). All track.files returned by __session.api().get_metadata_4_track(track_id_or_track) contain only formats up to OGG_VORBIS_320, as it did before I pulled this.

Did you confirm it worked properly for your setup, and if so, can you provide a few songs (preferably links or uuids) that you saw success with so that I can try to replicate it?

@akbad
Copy link
Copy Markdown
Contributor Author

akbad commented Oct 26, 2025

@Googolplexed0 I tried the same thing and sadly it didn't work properly. I looked into it and my conclusion is that everything in this PR is indeed needed to support FLAC, and it's simply the Spotify endpoints used that aren't serving FLAC files in response to our requests.

My guess is that there's some secret sauce in the Spotify desktop client's requests that we need to replicate somehow here in order to get it to serve us FLAC files. I tried tracing how Spotify's desktop client does it (i.e. using mitmproxy) but didn't have enough time to completely figure it out (and won't for a little while sadly). Whenever this is done, it would probably provide the missing piece to the puzzle.

@Googolplexed0
Copy link
Copy Markdown
Contributor

My guess is that there's some secret sauce

I would assume you are correct, given how long it took them to roll out this particular feature.

but didn't have enough time to completely figure it out (and won't for a little while sadly)

Bummer. If you have some advice on how I could help with the snooping efforts, let me know. I would really like to gain this functionality if possible.

@yeralin
Copy link
Copy Markdown
Contributor

yeralin commented Oct 29, 2025

Created an issue to track this #320

ljrk0 added a commit to ljrk0/zotify that referenced this pull request Nov 13, 2025
@ljrk0
Copy link
Copy Markdown

ljrk0 commented Nov 15, 2025

I tried starting to trace as well but didn't conclude anything productive. FWIW, I found the following setup quite nice to trace (to circumvent certificate pinning etc.), although also a bit over-engineered.

  1. Use Android Studio to fire up a VM. VM should support have "play enabled"
  2. Emulator: Install Google services/OpenGapps (optional?)
  3. Emulator: Install Spotify APK from: https://www.apkmirror.com/apk/spotify-ab/spotify-music-podcasts/spotify-music-and-podcasts-9-0-96-648-release/

Then, use HTTPToolkit to Intercept from Android Emulator using Frida.
Optionally, set-up Burp in combination with HTTPTk:

  1. Export Burp Proxy Cert.
  2. Configure Burp 127.0.0.1:8080 as upstream proxy in HTTPToolkit and import the cert

You can also use e.g. blackboxprotobuf to decode some protobufs. But I'm too tired for that now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants