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

Add support for high quality YouTube Music streams for Premium users. #221

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

ReneHollander
Copy link
Contributor

This requires to supply yt-dlp with a cookiefile that exists on disk.
The musicapi_cookie config option is replaced with a musicapi_cookiefile option. This also allows the cookies to be better
protected by giving the file proper permissions or using Docker secrets in a Docker deployment.

Some nasty glue code is needed to generate a Cookie header from the CookieJar (There is no functionality in the Python stdlib to do this cleanly). A better approach would be to refactor all code to take a CookieJar opbject (including ytmusicapi) that can be natively used in requests and urllib (assuming it is used somewhere). As this requires some work on a dependency I am refraining from doing this in this PR.

This requires to supply yt-dlp with a cookiefile that exists on disk.
The `musicapi_cookie` config option is replaced with a
`musicapi_cookiefile` option. This also allows the cookies to be better
protected by giving the file proper permissions or using Docker secrets
in a Docker deployment.

Some nasty glue code is needed to generate a Cookie header from the
CookieJar (There is no functionality in the Python stdlib to do this
cleanly). A better approach would be to refactor all code to take a
CookieJar opbject (including ytmusicapi) that can be natively used in
requests and urllib (assuming it is used somewhere). As this requires
some work on a dependency I am refraining from doing this in this PR.
@natumbri
Copy link
Owner

Thanks @ReneHollander - this is an interesting idea, and doesn't look too complicated. Appreciate you taking the time to submit. I'll have a look when I get a chance, and get back to you.

@sigma67 might be interested in a PR allowing ytmusicapi to take a Cookie Jar object, if that will make proper authentication from within the library easier (see sigma67/ytmusicapi#10)?

@sigma67
Copy link

sigma67 commented Jan 18, 2022

Sounds interesting, can you make a proposal for integrating this without breaking ytmusicapi for existing users?

Might be possible to pass cookiejar cookiefile as filepath and detect whether the file is json (current assumption) or a cookiejar, depending on the file type.

@ReneHollander
Copy link
Contributor Author

Thanks for the input! I will try to refactor the code to allow the usage of cookiejar.
I hope I can get to it next week :)

@laur89
Copy link

laur89 commented Mar 9, 2022

@ReneHollander any updates?

@ReneHollander
Copy link
Contributor Author

@laur89 sadly no. I didn't get to setup mopidy/snapcast yet, as it's impossible to order Raspberry Pis currently. So I didn't need this functionality and didn't spend time finishing it.

@fatg3erman
Copy link
Contributor

This would be really cool to add if it's still possible. Mopidy-YTMusic has the ability to play high quality streams, but that plugin has a bunch of other issues that make this one better.

@natumbri natumbri merged commit 9e81ab4 into natumbri:develop Oct 7, 2022
@natumbri
Copy link
Owner

natumbri commented Oct 7, 2022

Thanks @ReneHollander for the code, and @fatg3erman for the reminder. This seems to work ok, so I merged it. 256k audio unlocked.

@natumbri
Copy link
Owner

natumbri commented Oct 7, 2022

Uh oh; looks like it might not work completely yet - see #234

@fatg3erman
Copy link
Contributor

Thanks for jumping on it so quickly. I'll try some tests in the next few days, missing playlists are not a thing I care about. If this works well I think I've found my Spotify replacement :)

Comment on lines 88 to 89
youtube.musicapi_cookie = config["youtube"].get("musicapi_cookie", None)
youtube.musicapi_cookiefile = config["youtube"].get("musicapi_cookiefile", None)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to provide None default to get(key), None is the default value by default.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You technically don't even need to use get() on Mopidy config objects, they already have a default value.

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.

None yet

6 participants