How does YouTube calculate the number of views for a video? - youtube

I have made an internal movie site in .Net.
I play the movie trailers using jw player. Now I want to know how to calculate the number of views for a video?
Is it possible through code?
PLease help.
NBL I dont have any database. I add the videos through an xml and the code reads the xml.

A simple approach is to tally the number of pageloads for the page that contains the video, rather than the number of times the video itself is played. First, create a table in your database that contains these fields:
DateTime date // date of pageloads -- we'll get to this in a minute
int videoID // Unique Identifier for the video loaded
int count // Number of pageloads
When I tally pageloads, I do them by day so I can compile statistics over time. Of course, you can use a different granularity depending on your particular needs.
Additionally, I don't particularly like writing to the database with each pageload, so I have a class I've written that caches the hits, then writes them after every hundred hits or so.
In this class, I also retain each user's IP address. This allows me to ferret out duplicate pageloads. A subsequent task, which I'm working through in my own hitcounter, is to triage humans, legitimate spiders and unwelcome bots.

Not sure exactly what you need.. but you can handle the play command (button or loading... however your videos are played), and attach that to a counter that you save in your database.
We would need a lot more (code set, video codec and such) before giving more.

You can also create a separate table with these columns :
VideoId
IP adress
And add a row each times an user watch a video...
Then you will calculate unique watch and not duplicate
(Instead of ip adress you can store userId if your users are registered)

The database would have a table for videos, including a Hits column.
When you request the page from the server, the server would execute a stored procedure that adds +1 to the 'Hits' column.

If you are embedding videos on your page, it's worth being aware of YouTube's policy on the question of autoplaying those videos, in relation to the official viewcount. If in the player you set autoplay = true, or equivalent, then the YouTube view count doesn't increase. This is to counter spammy viewcount auto-augmentation pages. The user has to click on the play button, and watch all, or at least most, of the video to count as a view.

Related

YouTube API V3 - How to get ALL game live streams

I'm trying to get "ALL" game live streams from youtube using API.
The way I first used is through "Search.list" with parameters: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&eventType=live&maxResults=50&type=video&videoCategoryId=20. But in this way when I try to iterate results using PageToken, I can only get around 100 results while in the API response I can see "totalResults" is around 2000. Then I came into this topic and realized that "Search.list" is actually kind of "ranking" algorithm instead of "fetch all data from DB", which means "totalResults" is just an estimated number of results.
Then I came to use "liveBroadcasts.list" but it returns no results: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.liveBroadcasts.list?part=id&broadcastStatus=active&maxResults=50&_h=8&
And for other APIs, they either need channelId or other ids.
Is there any way to get all game live streams regardless of any ids?
According to Youtube Category ID list, Gaming resides on number 20 category. In case you want to try a different category in the future, instead of videoCategoryId=20, you can try videoCategoryId=31 - that's for Anime/Animation.
Try to run this on your browser to get all live streams:
https://www.googleapis.com/youtube/v3/search?part=snippet&eventType=live&type=video&videoCategoryId=20&regionCode=US&maxResults=50&key=SERVER_API_KEY_HERE

Youtube API V3: Total comments count [Videos]

I want to get all video comments of a channel. At the moment I'm proceeding like this:
1.) Getting all video ids of a channel (1 quota)
2.) Sending new request with "part: statistics" and getting the total comment count to a youtube video (2 Quota)
It's polling in 30 seconds intervall and I wanted to reduce the quota. Therefore is there a possibility to query whether there are any new comments for a channel videos (Total amount of comments for a channel including channel comments would be fine too)? Like saving the old value of total amount of comments and comparing it with the new amount of the query?
No, from my experience.
I would not use video's commentCount.
- you can pull over 260 comments from a video whose comment count is only 243. https://www.youtube.com/watch?v=87xYGDR_eME
I would not try optimizing by stopping at recent comments.
- this would work for threads, but each thread has replies. So you have to check each thread anyways just to see if they have new replies.
- note: it's dangerous to use commentThreads' reply mode, as it may only return a subset of replies. Instead get a comment list using parentId.
Perhaps, if you sort by time and save the id of comments you've collected, you can use cheap requests like id to figure out which comments are new and pull them with snippet.
- stop when you get to an id you've already gathered.
This may not be simple though because publishedAt or updatedAt leave two questions:
will an old comment be bumped to the top if it's edited? If so, you can't stop once you recognize a comment id, because it might have jumped ahead of new comments (unless the change the id when it's edited).
will the old comment not be bumped if edited? If this is the case, you need to check snippet for each comment as the textDisplay may be different. In this case I can see no optimizations.

How long until a song shows up on the Musicbrainz XML/JSON service?

I just added a release that wasn't on musicbrainz before:
http://musicbrainz.org/release-group/8f6f6155-20dd-4960-9381-47805e6b50f5
Here's my query for that song that's returning 0 results:
http://musicbrainz.org/ws/2/recording/?query=recording:%22When%22%20AND%20artist:%22Life+On+Planet+9%22%20AND%20dur:[268473%20TO%20293473]%20AND%20number:6%20AND%20release:%22Bittersweet
%22&limit=1&fmt=json
and the actual song:
http://musicbrainz.org/recording/78c84a0c-8b79-46ff-af4d-653ce52540ca
It turns out that while the changes to the database show up instantly, the indexing for search for the XML service takes at least a day, maybe less than that.
Either way, the results showed up the next day.

Max-results value is too high.YouTube API

I'm trying to load the first 100 videos of a YouTube channel and I can only load 50 videos. I always get this error message
Max-results value is too high. Only up to 50 results can be returned per query.
and I'm using this URL.
http://gdata.youtube.com/feeds/api/users/shaytards/uploads?&max-results=100
I'm not sure if I need any kind of developer key to load 100 results. Even if you know a way to load videos 75-100 would be great but any help would be appreciated.
The Youtube data API requires you to set up your own pagination if you need to get more than 50 results. In this case, then, you would set max-results to 50 and do the query, then on your page have some sort of "next" button (or however you want to implement your pagination) that would trigger a new call (either through ajax, a new page, or whatever your own workflow is). This new call would be to the same data feed, but you'd append the parameter &start-index=51 so that you'd get 50 more results, numbered 51-100. You can continue on like this up to 1000 results.
See https://developers.google.com/youtube/2.0/reference#Paging_through_Results for more details.
In the YouTube Data API V3 it is a little different. Each search query returns a "nextPageToken" that can be used in a subsequent query for more results. Documentation: https://developers.google.com/youtube/v3/guides/implementation/pagination

safeSearch filter videos but it is not ip restriction. Is it a bug?

Whether i tried http://gdata.youtube.com/feeds/api/users/t_vuWv0C8mbjQAe-5RKKrQ/uploads?v=2&start-index=1&max-results=50&prettyprint=True&safeSearch=none, http://gdata.youtube.com/feeds/api/users/t_vuWv0C8mbjQAe-5RKKrQ/uploads?v=2&start-index=1&max-results=50&prettyprint=True&safeSearch=moderate, http://gdata.youtube.com/feeds/api/users/t_vuWv0C8mbjQAe-5RKKrQ/uploads?v=2&start-index=1&max-results=50&prettyprint=True&safeSearch=strict
The result is filtered and only return 1 video.
However, if i remove safeSearch parameter , http://gdata.youtube.com/feeds/api/users/t_vuWv0C8mbjQAe-5RKKrQ/uploads?v=2&start-index=1&max-results=50&prettyprint=True, i can get many videos.
I didn't think it's related to ip restriction, the feed didn't return yt$state and something like ""This video is not available in your region.". I can play all videos on the browser with the same ip. it is not related to restriction parameter, http://gdata.youtube.com/feeds/api/users/t_vuWv0C8mbjQAe-5RKKrQ/uploads?v=2&start-index=1&max-results=50&prettyprint=True&restriction=127.0.0.1&safeSearch=none still return 1 video.
My question is, what restriction exactly cause safeSearch filter my result, if not ip restriction, what else? 18+ video?
You're getting back different results because your first set of queries all go against the search index, and your other query goes against the backend database. This is explained in more detail at http://apiblog.youtube.com/2012/03/keeping-things-fresh.html

Resources