Youtube Music
Communication with YT Music is unofficial and not supported or endorsed by Google. This means that this integration may stop working at any time if Google decides to change how YT Music works in the browser.
Due to monitoring being unofficial, listening history from YTM can be inconsistent and can cause missed scrobbles.
See the FAQ for a detailed explanation, how to see more details about MS's detection of tracks, and how to properly report an issue.
Authentication
Only one of these methods needs to be used.
- Cookies
- OAuth Client
- YoutubeTV
Use instructions from
- https://github.com/patrickkfkan/Volumio-YouTube.js/wiki/How-to-obtain-Cookie or
- https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html#copy-authentication-headers
to get the Cookie value from a browser.
It is highly recommended to get the cookie from an Incognito/Private Session to limit the chance the session is invalidated from normal browsing.
Add the cookie to your ytmusic.json config in data or as an ENV:
{
"type": "ytmusic",
"enable": true,
"name": "MyYTM",
"data": {
"cookie": "__Secure-1PSIDTS=sidts-CjEB3EgAEvCd-......"
},
"options": {
"logAuthUpdateChanges": true,
"logDiff": true
}
}
If MS gives you authentication errors (session invalidated) at some point in the future follow the same instructions to get new cookies.
As of Sept 25' OAuth clients no longer seem to have permission to access the YTM service, as reported by the upstream YTM library developer and several other users.
If you have existing, working OAuth credentials keep using them but there is no gaurantee they will continue to work.
If you are setting up the YTM Source for the first time you should first try to use Cookies.
Based on the instructions from here...
- Login to Google Cloud console (create an account, if necessary)
- Go to APIs and services.
- Configure the OAuth consent screen
- Use the old experience if possible
- If new is unavoidable then do not fill out any branding and under Authorized Domains you can delete the empty one (in order to save)
- Add yourself as an authorized user
- Navigate to Credentials
- Create Credentials -> choose "OAuth client ID"
- Application Type is Web Application
- Name is whatever you want, leave Authorization Javascript origins blank
- Authorized redirect URIs
- This must be exactly the same as what is displayed in MS! For now leave it blank so we can generate it from MS first
- Create
- In the newly created client popup save the Client ID and Client Secret, then copy them into
ytmusic.jsonor appropriate ENVs:
- In the newly created client popup save the Client ID and Client Secret, then copy them into
- Create Credentials -> choose "OAuth client ID"
- Configure the OAuth consent screen
{
"type": "ytmusic",
"enable": true,
"name": "MyYTM",
"data": {
"clientId": "8910....6jqupl.apps.googleusercontent.com",
"clientSecret": "GOCSPX-WGXL6BSuQ343..."
},
"options": {
"logAuthUpdateChanges": true,
"logDiff": true
}
}
Now, start MS and during the YTMusic startup it will log something like this:
Will use custom OAuth Client:
Client ID: ...
Client Secret: ...
Redirect URI: http://localhost:9078/api/ytmusic/callback?name=MyYTM
If the beginning of the Redirect URI (before api) is EXACTLY how you would reach the MS dashboard from your browser (EX http://localhost:9078) then edit your google oauth client section for Authorized redirect URIs and add the URL MS has displayed.
If it is NOT EXACTLY the same you either need to set MS's base url or you can provide your own (Custom) Redirect URI for MS to use by setting it in ytmusic.json or ENV.
Using a Custom Redirect URI
The three parts of the URL that must be the same:
- it must start with
api(after domain or subdirectory IEmy.domain.tld/api...orwhatever.tld/subDir/api... - it must end in
ytmusic/callback - It must include
name=[NameOfSource]in the query string
Remember to add your custom URL to the Authorized redirect URIs section in the google oauth client!
{
"type": "ytmusic",
"enable": true,
"name": "MyYTM",
"data": {
"clientId": "8910....6jqupl.apps.googleusercontent.com",
"clientSecret": "GOCSPX-WGXL6BSuQ343...",
"redirectUri": "http://my.custom.domain/api/ytmusic/callback?name=MyYTM"
},
"options": {
"logAuthUpdateChanges": true,
"logDiff": true
}
}
AFTER changing the Authorized redirect URIs on Google Cloud console you may need to wait a few minutes for it to take affect. Then restart MS. From the dashboard click (Re)authenticate on the YTmusic source card and follow the auth flow:
- On the screen about "testing" make sure you hit Continue (not Back To Safety)
- Make sure to select ALL scopes/permissions/grants it asks you about
Select what [YourAppName] can access-> Select all
Once the flow is finished MS will get the credentials and start polling automatically. You should not need to re-authenticate again after restarting MS as it saves the credentials to the /config folder.
Using the built-in YoutubeTV authentication is unlikely to work due to Google restricting what permissions TV clients can have. This authentication method should not be used.
To authenticate start multi-scrobbler with an empty YT Music configuration. An authentication URL/code will be logged in additon to being available from the dashboard.
ERROR: Sign in with the code 'CLV-KFA-BVKY' using the authentication link on the dashboard or https://www.google.com/device
Visit the authentication URL and enter the code that was provided (also available on the dashboard). After completing the setup flow MS will log Auth success and the YT Music dashboard card will display as Idle after refreshing. Click the Start link to begin monitoring.
Configuration
- ENV
- File
- AIO
| Environmental Variable | Required? | Default | Description |
|---|---|---|---|
| YTM_COOKIE | No | Value for Cookie Authentication | |
| YTM_CLIENT_ID | No | Client ID for OAuth Athentication | |
| YTM_CLIENT_SECRET | No | Client Secret for OAuth Athentication | |
| YTM_REDIRECT_URI | No | A custom redirect URI for OAuth Athentication | |
| YTM_LOG_DIFF | No | false | Log YTM history changes |
[
{
"name": "MyYTMusic",
"enable": true,
"clients": [],
"data": {
"cookie": "__Secure-1PSIDTS=sidts-CjEB3EgAEvCd-......",
"clientId": "891098404....apps.googleusercontent.com",
"clientSecret": "GOCS..."
},
"options": {
"logDiff": true
}
}
]
or explore the schema with an example and live editor/validator
{
"sources": [
{
"name": "MyYTMusic",
"enable": true,
"clients": [],
"data": {
"cookie": "__Secure-1PSIDTS=sidts-CjEB3EgAEvCd-......",
"clientId": "891098404....apps.googleusercontent.com",
"clientSecret": "GOCS..."
},
"options": {
"logDiff": true
},
"type": "ytmusic"
}
]
}
or explore the schema with an example and live editor/validator