Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find file encoding and decode?

I'm trying to understand how to decode a file that Spotify leaves on my system.

The file in question is called context_player_state_restore and lives in /Users/<myuser>/Library/Application Support/Spotify/PersistentCache/, so obviously the expectation is that its structure (and now encoding likely) can change without warning.

The Spotify app updates that file at regular time intervals with the currently playing song, the current context (e.g. currently playing playlist), and some other useful stuff like the history of played tracks.

I want to parse the information in that file for an app I'm building. (I can use the Spotify API for some of this data, but the local file contains more useful information, is immediate (no delay in API calls), and I can react to any changes on it).

Until recently that file was an UTF-8 JSON file and could be parsed with JSON.parse(data).

Recently however, Spotify has changed that JSON / UTF-8 encoding.

Currently, opening that file with vscode (with UTF-8 encoding) gives back some legible text, indicating that some of the JSON structure has been kept, but also shows a lot of illegible text – the odd question mark symbols �� and various UTF characters that don't belong e.g. Ω.

In short, I'd like to understand:

  • whether I can find out what encoding Spotify is now using for this file
  • and whether it is possible to decode the file back to JSON (or a similar format) so it can be easily parsed

Gist link to file dump as seen by vscode

Google Drive download of file

Gist link to hexdump of file (obtained with hexdump -C context_player_state_restore > context_player_state_restore.hexdump)

like image 909
Alex Avatar asked Oct 30 '25 19:10

Alex


1 Answers

Regarding your question

what encoding Spotify is now using for this file

I believe it is the encoding used by Google Protocol Buffers. That page gives the example of the string "testing" encoded as 12 07 [74 65 73 74 69 6e 67], and this pattern "0x12 followed by the string length followed by the UTF-8 encoding of the string" appears throughout your context_player_state_restore file.

If you know the corresponding .proto file, you can decode context_player_state_restore with the protobufjs package.

like image 74
Heiko Theißen Avatar answered Nov 01 '25 09:11

Heiko Theißen