amnrst / youtube-like-to-view-ratio

11 stars 1 forks source link

Show it on the other youtube pages #3

Open qo4on opened 2 years ago

qo4on commented 2 years ago

To see the like to view ratio before you click on the video. VidIQ did this: image

aminroosta commented 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.

qo4on commented 2 years ago

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="{&quot;percent&quot;:98,&quot;likes&quot;:422433,&quot;dislikes&quot;:9657}">98%</div></span>
aminroosta commented 2 years ago

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.

qo4on commented 2 years ago

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.

aminroosta commented 2 years ago

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.

qo4on commented 2 years ago

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.