问题
I'm trying to go back and sync completed or in-progress live event with real-world timestamps (for example, a twitter play-by-play.) I don't own the live events in question. Obviously this is only useful for events that can be rewound or replayed (such as many of the gaming-related broadcasts)
Is there a way to retrieve the start time of a live event?
I've tried the following:
Using player.getDuration():
If the currently playing video is a live event, the getDuration() function will return the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.
This doesn't seem to be always accurate - if a live event has a set broadcast duration, this seems to instead return the total time that the broadcast is scheduled for. here is a random video that exhibits that behaviour: http://www.youtube.com/watch?v=e-Bb5F8Jcwg (found via http://www.youtube.com/live/all)
I've also tried using the data api and grabbing the publish time from the snippet, but this usually appears to be a few hours or days before the broadcast actually begins.
As a non-content owner, is there any way to retrieve this time?
Thanks!
EDIT:
After looking further, I found developers.google.com/youtube/2.0/… which appears to offer this information under the yt:when for each event... so I guess my revised question would be - is there a way to retrieve this given a video ID, or do I always need to find it through the live events api?
回答1:
You can use Data API v3 for this.
You can do a videos->list with id=VIDEO_ID
You can get duration from contentDetails.duration from the response.
If the content was your own, you could use v3 Live Streaming API for this.
You can do a liveBroadcasts->list with id=VIDEO_ID
You can calculate duration with snippet.actualStartTime and snippet.actualEndTime from the response.
来源:https://stackoverflow.com/questions/18068378/how-to-retrieve-the-start-time-of-a-live-event-on-youtube