Open qo4on opened 2 years ago
I'm not able to find the like-count on the main page.
The attached data on each video document.querySelector('ytd-grid-video-renderer').data
only contains the view-count.
It's not just for the main page. The ratio is shown on all pages next to the video thumbnails like suggested, channel, search, trends... I believe that VidIQ gets the number of likes through youtube api (replace with your key): https://www.googleapis.com/youtube/v3/videos?key=AIzaSyDJGr5kUk92BcJSQJu90UPqbQ8-VTutDuw&id=kxOuG8jMIgI&part=statistics
Selector and span they used:
#metadata-line > span:nth-child(4) > div
<span data-mount-id="f41d5d57d5aaff5fa97220659a43041d717f582d"><div class="vidiq-like-ratio great" data-react-popover="LikeRatioPopover" data-react-popover-props="{"percent":98,"likes":422433,"dislikes":9657}">98%</div></span>
Ok, that definitely works.
I have two concerns before implementing this. First is that YouTube data API v3 has a quota limit of 10,000 units per day. If this extension becomes popular that will certainly be a problem. The second concern is that I don't want to ship my API key with the extension.
Ask the user to use his own api key. In this case, the extension will work faster and use less internet bandwidth. If the user refuses or he exceed his quota limit, you can always load the page via get request and get the number of likes from there.
The target users are not developers, since they could fork the project off and do whatever they want. So asking the users to use an API key is not a real solution.
I did try the second approach tho', basically one request per video to get https://www.youtube.com/watch?v=${video_id}
and then extract like-count.
That page is (sadly) about 500KB
which makes it impractical, not only it is slow to get all those pages, eats too much bandwidth.
But I really like your idea, and I wish I could find an acceptable way to implement it.
A user does not need to be a developer to copy-paste the key. I've seen many browser extensions that ask for this. Besides, it's an option, he may choose not to do that. VidIQ also showed the ratio with a slight delay when the main page is loaded. So, it is not a problem.
To see the like to view ratio before you click on the video. VidIQ did this: