-
Notifications
You must be signed in to change notification settings - Fork 273
Fix for #711: Implement custom playlist thumbnail uploads #866
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #866 +/- ##
==========================================
- Coverage 95.55% 94.33% -1.22%
==========================================
Files 46 46
Lines 2543 2578 +35
==========================================
+ Hits 2430 2432 +2
- Misses 113 146 +33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ytmusicapi/mixins/playlists.py
Outdated
| moveItem: str | tuple[str, str] | None = None, | ||
| addPlaylistId: str | None = None, | ||
| addToTop: bool | None = None, | ||
| thumbnail: str | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use a pathlib.Path for this?
ytmusicapi/mixins/playlists.py
Outdated
| response = self._send_request(endpoint, body) | ||
| return response["status"] if "status" in response else response | ||
|
|
||
| def _upload_playlist_thumbnail(self, filepath: str) -> str | JsonDict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing the protocol! Could you add a test as well?
You could for example use one of the existing owned playlists on the test account and use an image that you add to the test data.
The action is idempotent, so you can simply keep reuploading the same image during the test.
ytmusicapi/mixins/playlists.py
Outdated
|
|
||
| headers = self.headers.copy() | ||
| # Get upload_url by sending an empty request to the upload endpoint | ||
| upload_url = "https://music.youtube.com/playlist_image_upload/playlist_custom_thumbnail" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the constant here: https://github.com/sigma67/ytmusicapi/blob/main/ytmusicapi/constants.py#L1
- Updated and to use for file handling. - Replaced hardcoded URL with constant. - Added to to verify the full upload flow. - Added fixture for live testing.
- The endpoint rejects binary uploads if the is set to . - Removed the header before the second request (binary upload) to fix the 400 Bad Request error in integration tests.
|
@sigma67 here's what I have done so far:
Lastly, YoutubeMusic requires an image with a minimum dimension of 360x360. I couldn't find a straightforward way to implement image size checking, so I didn't add this check. For the most recent build, I had tested the |
…integration fails
|
@sigma67 I fixed the mypy and ruff issues. What do you suggest? |
|
I'm getting the same error locally, so not sure how I can help you here |
|
If you suspect it's related to the brand account, you can also try using a different fixture like yt_auth. Although in the end it should also work with the brand account |
|
I now recall something else @sigma67 . To be able to add custom playlist thumbnails at all, you need to first go to the playlist and enable the function by verifying your phone number. Do you think this could be the cause of the 403 error? |
|
My account has a verified phone number. I can change the image just fine on the web UI. |
|
You should double check that you are using the same account as with the |
Closes #711
This PR adds the ability to upload custom thumbnails to playlists via edit_playlist.
Changes:
Testing:
Test used:
yt.edit_playlist(playlistId="...", thumbnail="cover.jpg")P.S.: I am happy to add a unit test for
_upload_playlist_thumbnailif you could point me to an example of how you prefer to mock upload requests.