tombulled / innertube

Python Client for Google's Private InnerTube API. Works with YouTube, YouTube Music and more!
https://pypi.org/project/innertube/
MIT License
297 stars 20 forks source link

How do you get the number of likes? #44

Closed qo4on closed 1 year ago

qo4on commented 1 year ago

Is it even possible to do this through the api without loading the page itself? I mean the full number

from innertube import InnerTube, Client
from pprint import pprint

video_id = 'zL3wWykAKfs'
web_remix = InnerTube("WEB_REMIX")
data = web_remix.music_get_queue(video_ids=[video_id])

print(data['queueDatas'][0]['content']['playlistPanelVideoRenderer']['longBylineText']['runs'][-1]['text'])
# 262K likes
tombulled commented 1 year ago

Hi @qo4on, I've just taken a quick look into this and can't seem to find a way to get the full like count. I'll keep fiddling and will let you know my findings

tombulled commented 1 year ago

It looks like this is possible using the official YouTube Data API - https://developers.google.com/youtube/v3/ There's a community provided API that'll provide the full value as well, which looks like it might be scraping the YouTube Data API behind the scenes - https://returnyoutubedislikeapi.com/votes?videoId=zL3wWykAKfs

tombulled commented 1 year ago

Success!

from innertube import InnerTube

video_id = "zL3wWykAKfs"

client = InnerTube("WEB")

data = client.next(video_id)

like_count = data["contents"]["twoColumnWatchNextResults"]["results"]["results"]["contents"][0]["videoPrimaryInfoRenderer"]["videoActions"]["menuRenderer"]["topLevelButtons"][0]["segmentedLikeDislikeButtonRenderer"]["likeButton"]["toggleButtonRenderer"]["defaultText"]["accessibility"]["accessibilityData"]["label"].split(" ")[0]

print(f"Total likes: {like_count}")
Total likes: 262,031
tombulled commented 1 year ago

In case it's helpful, the NewPipe repository can be handy as a reference for how they scrape data out of the InnerTube API :slightly_smiling_face: - https://github.com/TeamNewPipe/NewPipeExtractor/blob/6bdd698c259c4301d8ee6cb9ef226b5d35f49ca8/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java#L415

qo4on commented 1 year ago

Thank you, that's very interesting! But how do they connect to YouTube itself, what is the first request they make?

tombulled commented 1 year ago

Unfortunately I'm not familiar with their specific implementation, however I imagine they're doing something very similar