mirror of
https://github.com/sigma67/ytmusicapi.git
synced 2026-04-25 15:26:01 +03:00
[GH-ISSUE #42] Fetch song metadata by videoId #31
Labels
No labels
a/b
bug
documentation
enhancement
good first issue
help wanted
invalid
pull-request
question
wontfix
yt-error
yt-update
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ytmusicapi#31
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JGMEYER on GitHub (Jul 9, 2020).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/42
[Creating ticket per CONTRIBUTING.rst]
Context:
YouTube Music urls already provide the id to the video. It would be nice to be able to fetch a video's metdata, e.g. name, artists from this videoId. Similar to get_album() for albums.
get_song(self, videoId)could return a song's metadata.How this feature is missing:
From reading the documentation, there doesn't seem to be an endpoint to retrieve this information or a set of chained function calls to achieve this use case.
Acceptance criteria:
This ticket is to gather information on the set of requirements and to implement the method in class
YTMusic, if currently feasible.This ticket can be closed under any of the following conditions:
get_song(self, videoId)has been implemented inYTMusic(with corresponding unit/integration tests) for fetching song metadataI'm not yet sure about the limitations on the api for fetching this information, or futhermore if this would somehow be blocked by #10. I (@jgmeyer) am open to help develop this feature, but may need some guidance.
@sigma67 commented on GitHub (Jul 9, 2020):
This should be possible. YouTube Music uses a different API (www.youtube.com/get_video_info) than the one usually used in ytmusicapi for this purpose (music.youtube.com). But I believe the request should work using the same cookies that the rest of ytmusicapi uses. The endpoint was reverse engineered here: https://tyrrrz.me/blog/reverse-engineering-youtube
The response needs to be URL decoded, afterwards you can find the interesting parts in player_response (JSON containing all the info), more specifically the key
videoDetails. Below I've extracted an example. Is this what you had in mind?The individual items probably need to be processed a bit, since they still contain '+' instead of spaces.
@JGMEYER commented on GitHub (Jul 9, 2020):
That’s pretty close. The disadvantage I see here is that you have to parse the video ‘title’ to “best guess” the song ‘name’ and ‘artist’. Versus being able to retrieve these values explicitly in a response from the json. Maybe the namings of YTMusic videos are better standardized than YouTube’s? Or maybe they’re one in the same. I’m still familiarizing myself with the platform.
@sigma67 commented on GitHub (Jul 9, 2020):
I think you actually get that info if it's a song (and not a video as above). I tried with a public track from YTMusic:
and a private track
The
streamingDatakey contains some interesting info as well, such as technical video details and streaming URLs for different playback qualities.Here's the full response: get_video_info_json.txt
@sigma67 commented on GitHub (Jul 13, 2020):
I did some more research and it seems YTMusic actually uses the next() endpoint (https://music.youtube.com/youtubei/v1/next) to get the info shown in the player. However, the info provided by that endpoint is even less structured as get_video_info, as it simply provides the "bylines" shown at the bottom, without specifying whether the info is artist, like, views, album etc.
Here's an example for a music video:
and another for a regular song:
I do believe that the
nextendpoint should be implemented eventually, as it provides a way to retrieve radio mix playlists for a given song. I believe that YouTube'sget_video_infois better suited for getting metadata however. It also provides the YouTube video's auto generated description, which can be parsed in a more structured fashion than YTMusic's unstructured bylines.@JGMEYER commented on GitHub (Jul 13, 2020):
Good find! Yeah, it does seem the youtube api would be better suited for this with how unstructured the youtube nusic api response is. Probably makes this feature out of this project's scope? I haven't actually gotten the chance yet to follow the reverse engineered steps, but I skimmed it over and it looked straightforward enough. Just need to get some spare time again to tinker with it.
@sigma67 commented on GitHub (Jul 14, 2020):
I already made some progress on the
get_video_infoimplementation and pushed to the branch feature/get_song (referenced above).Let me know what you think. Feel free to add or change things if necessary
@sigma67 commented on GitHub (Jul 20, 2020):
Are you still interested in this issue @JGMEYER ? Otherwise I'll go ahead and merge it into master
@JGMEYER commented on GitHub (Jul 20, 2020):
Please feel free to merge. I managed to use one of the youtube endpoints
for my project from the blog you posted, but I’d be happy to test out any
release that contains these changes :)
On Mon, Jul 20, 2020 at 04:35 sigmatics notifications@github.com wrote:
--
Justian Meyer
Georgia Institute of Technology
Computer Science '14