feat(models): response models for the upload-library methods - #1008
Open
atirna wants to merge 1 commit into
Open
feat(models): response models for the upload-library methods#1008atirna wants to merge 1 commit into
atirna wants to merge 1 commit into
Conversation
get_library_upload_songs, get_library_upload_artist and get_library_upload_album now return UploadSong and UploadAlbum models deriving from YTMusicModel, per sigma67#987. Parsers construct the models directly; docstrings point at them instead of repeating the JSON shape. Uploaded items are similar to but not the same as regular songs (entityId, several absent fields), so the models are upload-specific until sigma67#983/sigma67#981 land; the leaf shapes match sigma67#981 so they can be re-homed later. get_continuations and get_continuation_contents take a TypeVar so a parse func returning models typechecks; dict parse funcs are unaffected. Part of sigma67#307.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_library_upload_songs,get_library_upload_artistandget_library_upload_albumnow return pydantic response models (UploadSong,UploadAlbum) deriving from theYTMusicModelbase landed in feat(models): add pydantic and the YTMusicModel dict-compatible base #1004ytmusicapi/parsers/uploads.py:parse_uploaded_itemsconstructsUploadSongdirectly, and a newparse_upload_albumassembles the album header plus tracksget_continuations/get_continuation_contentstake a TypeVar so a parse func returning models typechecks; the dict parse funcs everywhere else are unchangedCloses #987
Why
uploaded items are similar to but not the same as regular songs: they carry an
entityIdand lack several fields YTM-hosted songs have (isAvailable,videoType,setVideoId). since the song model from #983 and the shared leaf models from #981 are not merged yet, these are upload-specific models for now. the leaf shapes (Thumbnail,ArtistRef,AlbumRef) deliberately match what #981 plans, so re-homing them onto the shared models later is mostly a rename.one behavioural note for 2.0 consumers: with the #307 key-presence semantics, a field the API did not return is present with value
Noneinstead of being absent."album" in songisTrueeven when the song has no album column, andsong["album"]returnsNoneinstead of raising. dict-style access (song["title"],song.get("entityId")) keeps working through the mapping protocol, so code like the existingtests/mixins/test_uploads.pyflows is unaffected.Verification
pytest -o addopts='' tests/parsers tests/models -q: 103 passed. new tests intests/parsers/test_uploads.pycover: full song parse, missing fixedColumns / album column / thumbnails staying present asNone, unknown likeStatus falling back toINDIFFERENT, menu-less items skipped, a continuation page parsed through the model parse func, and albumduration_secondssummed over tracks (4:15 => 255, two tracks => 510)mypy(strict, repo config), cleanruff check .andruff format --check .: cleantests/mixins/test_uploads.pyare unchanged and run in CI with the repo credentials