Skip to content

Instantly share code, notes, and snippets.

@nsyntych
Created October 21, 2024 22:41
Show Gist options
  • Select an option

  • Save nsyntych/eb867b06dd4350e22785223b1af7696c to your computer and use it in GitHub Desktop.

Select an option

Save nsyntych/eb867b06dd4350e22785223b1af7696c to your computer and use it in GitHub Desktop.
Login to tidal API using PKCE and update strawberry player settings to support Hi-Res Lossless playback
#!/usr/bin/python3
import tidalapi
import json
from pathlib import Path
from configparser import ConfigParser
strawberry_conf_file_path = str(Path.home()) + "/.config/strawberry/strawberry.conf"
strawberry_conf_file = ConfigParser()
strawberry_conf_file.read(strawberry_conf_file_path)
session = tidalapi.Session()
session.login_pkce()
creds = {
"token_type": session.token_type,
"session_id": session.session_id,
"access_token": session.access_token,
"refresh_token": session.refresh_token,
}
strawberry_conf_file["Tidal"]["type"] = "2"
strawberry_conf_file["Tidal"]["streamurl"] = "2"
strawberry_conf_file["Tidal"]["oauth"] = "true"
strawberry_conf_file["Tidal"]["enabled"] = "true"
strawberry_conf_file["Tidal"]["client_id"] = session.config.client_id_pkce
strawberry_conf_file["Tidal"]["quality"] = "HI_RES_LOSSLESS"
strawberry_conf_file["Tidal"]["access_token"] = creds["access_token"]
strawberry_conf_file["Tidal"]["refresh_token"] = creds["refresh_token"]
with open(strawberry_conf_file_path, "w") as configfile:
strawberry_conf_file.write(configfile)
print(json.dumps(creds, indent=4))
@nsyntych
Copy link
Author

Obviously you need to get the deps first:
pip install configparser pathlib tidalapi
and then run:
python tidal_login.py

@guprobr
Copy link

guprobr commented Oct 31, 2024

nice!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@dhobern
Copy link

dhobern commented Feb 6, 2025

Wonderful - thanks. For any who want to know how to use this to add the right details to Strawberry, keep OAUTH enabled and look for the client_id row in in the .config/strawberry/strawberry.conf file created in your home folder. It's a 16 character string.

@Cajivah
Copy link

Cajivah commented Apr 8, 2025

@nsyntych I've just tried your script and had "Tidal not authenticated" error. Managed to solve it by adding two more parameters to the .conf file: token_type=Bearer and then country_code=PL because after adding the first one I get through login but had "Missing countryCode" error. Put PL here because I'm from Poland.

The full script is here: https://gist.github.com/Cajivah/df5bd06448a2f3bf09534b23d0928043

@NeonGOD78
Copy link

Have something changed using this ?
i have used it before without any problems but on my new arch box it times out every day ?

@catb0t
Copy link

catb0t commented Nov 3, 2025

@nsyntych I've just tried your script and had "Tidal not authenticated" error. Managed to solve it by adding two more parameters to the .conf file: token_type=Bearer and then country_code=PL because after adding the first one I get through login but had "Missing countryCode" error. Put PL here because I'm from Poland.

The full script is here: https://gist.github.com/Cajivah/df5bd06448a2f3bf09534b23d0928043

Works, nice!

@nsyntych
Copy link
Author

nsyntych commented Nov 4, 2025

Please use this revision from now on: https://gist.github.com/Cajivah/df5bd06448a2f3bf09534b23d0928043

( and hope they don't change something again soon :) )

@Cajivah thank you for the fix!

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