play counts in YouTube API watchhistory? - youtube-api

Has anyone had any success in deriving play counts from the YT API's watchHistory?
Play counts don't seem to be included directly, so I thought I could count occurrences of a specific video in my history to get a personal view count. But it looks like whenever you watch a video again it just gets moved to the top of your history, there are no dupes. Any secrets here?

Related

How to get the current view count of all videos on a channel from the youtube API?

While the subscription count in
www.googleapis.com/youtube/v3/channels?part=statistics
seems to be updated instantly, the views update around daily.
A workaround that I found was to list all videos in the "uploaded" playlist with
www.googleapis.com/youtube/v3/playlistItems?part=contentDetails
and iterate through them, calling
www.googleapis.com/youtube/v3/videos?part=statistics
for each. This seems to get the most accurate results, though it requires more than 3 credits for every uploaded video, thus using my quota up relatively fast.
Is there a faster way around the problem?
I would like to implement it on an ESP8266 so it would be preferable not to require a lot of storage or processing power.
You can get the view count by getting the liveStreamingDetails, the liveStreamingDetails object contains metadata about a live video broadcast. The object will only be present in a video resource if the video is an upcoming, live, or completed live broadcast. Then, under this, you will get the concurrentViewers. It will show the number of viewers currently watching the broadcast. The property and its value will be present if the broadcast has current viewers and the broadcast owner has not hidden the viewcount for the video
EDIT
Specific to your use case, I believe a 2-part API would help with your inquiry.
I'm thinking of you calling a search query to retrieve all videos of the channel. The Search resource will have the id.videoId that you'll concatenate as part of the list call. This will give you the statistics.viewCount of each video, which you'll need to add up to get the total channel view count.
Hopefully this helps with your inquiry.
Happy coding!

Does AVPlayer support live event rewind?

I'm using AVPlayer to play streamed content. AFAIK, there are 3 kinds of stream contents
Progressive download: like VOD, this is a complete video. I can rewind & forward and get the duration of the video
Live streaming: this is like watching a TV channel. I can't get the duration
Live event: like a football match
Correct me if I'm wrong.
My question is Can AVPlayer work with live event? For example, the football match starts at 7:00AM and is about to last for 2 hours. You open the stream at 8:00AM, can you rewind back? Does the AVPlayer update the duration continuously ?
Also, I found the currentPlaybackTime
For video-on-demand or progressively downloaded content, this value is
measured in seconds from the beginning of the current item. Changing
the value of this property moves the playhead to the new location. For
content streamed live from a server, this value represents the time
from the beginning of the playlist when it was first loaded.
Not sure what For content streamed live from a server, this value represents the time from the beginning of the playlist when it was first loaded. mean
I find this document to be useful Technical Note TN2288 Example Playlist Files for use with HTTP Live Streaming
Basic Video on Demand (VOD) Playlist
The index file is static and contains a complete list of URLs to all
media files created since the beginning of the presentation. This kind
of session allows the client full access to the entire program
Live Playlist (Sliding Window)
For live sessions, the index file is updated by removing media URIs
from the file as new media files are created and made available.
Event Playlist
However, with the EVENT tag, you cannot change the playlist at all;
you may only append new segments to the end of the file. They cannot
be added at the front. New segments are added until the event has
concluded, at which time the EXT-X-ENDLIST tag is appended
So technically, I think iOS AVPlayer can handle live event rewind, it only depends on how the server generates the playlist file

youtube api contentowner by video

We are a content owner who has multiple channels rolled up into our analytics
We are pulling each day's earnings from the Youtube API to store in our database, but we want the data available per-video and not just per-channel.
The only way I've found to get a single video's earnings for a particular day is to do it for each individual video, like so
GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=contentOwner%3D%3D<contentownerid>&start-date=2013-10-01&end-date=2013-10-01&metrics=views%2Cearnings&dimensions=day&filters=video%3D%3D<videoid>&sort=day&key={YOUR_API_KEY}
This, obviously, is not ideal. We have over 5000 videos we're trying to keep track of, and the number will only grow, so making thousands of API calls every morning is not a good solution.
Is there a way to get earnings reports for the whole channel, separated by video, for a given date range with a single API call? I would think I would set "dimension" to video, but that won't work with anything involving the monetary fields like earnings.

Do YouTube Player error events correspond to permanent or transient problems?

Is there a possibility that a YouTube video (streamed with help from YouTube API) can temporarily be in some sort of banned state, making it dispatch errorEvents with errorCodes 100, 101, 150, only to eventually come back to a normal state that doesn't dispatch errorEvents?
In my implementation, I store some information about youtube videos in a database. I delete information about videos that dispatch these errorEvents, since videos that do not work are not in my interest to show.
Now, the problem for me is if there is a video that only dispatches errorEvents for a short period of time, as it gets deleted from my system, but actually still works.
Is a common thing that videos temporarily or periodically dispatch errorEvents?
The Player API documentation gives an overview of reasons why onError might be triggered. You should be able to interpret from that whether the scenario you describe is likely or not.
For example, error 100 can be triggered when a video is private. It's obviously possible for the owner of a video to flip it back and forth between private and public, so whether you want to ignore that video id in the future is up to you—it depends on how likely you think it is that the video will be made public again.
Error 101 is triggered when a video isn't enabled for embedding. That's another option that can be changed by the owner of the video at any point. It's again up to you to determine whether you want to take the current state of the video into account and disregard that video id, or leave it in your system on the off chance that the owner makes it embeddable in the future.

How can I find the number of seconds a YouTube video was played?

I have access to a proxy server and I can find out the time a video was requested. The log has the form (time, IP, URL). I want somehow figure out for how many seconds did a particular user using IP address A watched a YouTube video. Any suggestions?
If you only have access to requests, you obviously can't tell the difference if someone just loaded a video or watched it.
So, the best you can do is to come up with a set of heuristics that tries to 'guess' it by observing certain actions of the user. Here are a few ideas:
Does you log count the requests for the video buffer itself? If it does, you can see how much of the video was actually loaded, and the watched time can't be more than that.
If you (quite naively, I guess) assume that they're finished watching when they request another video URL, you can use this as your trigger for ending a 'video session'.
Install Wireshark or similar and start watching activity from YouTube during the video. Can you identify if there's a request when advertising is shown, or the related videos are displayed when the video finishes?
In all honesty, though, I think it will be virtually impossible trying to derive such an specific metric like seconds watched from such limited data as the point in time a video was requested. Just think of what could mess up any strategy you come up with: the user could load several videos in different tabs in a burst, or he could load a video page, pause it and forget it for several minutes or hours before he does watch it.
In short: I don't think you'll get a reliable guess using only the data you have, but if you absolutely must at least try, observing network activity between client and YouTube that only happens when a video is in the 'playing state' (pulling advertisings, related videos, some sort of internal YouTube logging, etc) is probably your best bet. Even that probably won't have a granularity nearly close to seconds, though.

Resources