开发者

From a Youtube Data API search result feed, how can I determine if a video will display the copyright message and not play?

开发者 https://www.devze.com 2023-03-18 01:59 出处:网络
I am performing a searches using the Data API. Sometimes when I try to display the video results, I get these types of messages:

I am performing a searches using the Data API. Sometimes when I try to display the video results, I get these types of messages:

This video contains content from EMI, who has blocked it in your country on copyright grounds.

How can I determine if the video will not play and display this message instead from the search results?

Here is an example of a search I am doing:

http://gdata.youtube.com/feeds/api/videos?q=Explosions+in+the+Sky+So+Long++Lonesome

And here is the first result, which I try to display and get the copyright message:

{"id"=>"http://gdata.youtube.com/feeds/api/videos/jotDBl1vilg", "published"=>"2009-01-24T00:08:01.000Z", "updated"=>"2011-07-05T21:57:58.000Z", "category"=>[{"scheme"=>"http://schemas.google.com/g/2005#kind", "term"=>"http://gdata.youtube.com/schemas/2007#video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/categories.cat", "term"=>"Music", "label"=>"Music"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"explosions"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"in"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"the"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"sky"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"so"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"long"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"lonesome"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"eits"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"indie"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"rock"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"instrumental"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"austin"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"texas"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"music"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"video"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"solar"}, {"scheme"=>"http://gdata.youtube.com/schemas/2007/keywords.cat", "term"=>"system"}], "title"=>"explosions in the sky - \"so long, lonesome\"", "content"=>"jakefyfe.tumblr.com watch in high quality. \"so long, lonesome\" i didn't realize until now how many videos were already on youtube for this song. im going to leave it up anyway.", "link"=>[{"rel"=>"alternate", "type"=>"text/html", "href"=>"http://www.youtube.com/watch?v=jotDBl1vilg&feature=youtube_gdata"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.responses", "type"=>"application/atom+xml", "href"=>"http://gdata.youtube.com/feeds/api/videos/jotDBl1vilg/responses"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#video.related", "type"=>"application/atom+xml", "href"=>"http://gdata.youtube.com/feeds/api/videos/jotDBl1vilg/related"}, {"rel"=>"http://gdata.youtube.com/schemas/2007#mobile", "type"=>"text/html", "href"=>"http://m.youtube.com/details?v=jotDBl1vilg"}, {"rel"=>"self", "type"=>"application/atom+xml", "href"=>"http://gdata.youtube.com/feeds/api/videos/jotDBl1vilg"}], "author"=>开发者_开发百科{"name"=>"jakefyfe", "uri"=>"http://gdata.youtube.com/feeds/api/users/jakefyfe"}, "comments"=>{"feedLink"=>{"href"=>"http://gdata.youtube.com/feeds/api/videos/jotDBl1vilg/comments", "countHint"=>"43"}}, "group"=>{"category"=>"Music", "content"=>[{"url"=>"http://www.youtube.com/v/jotDBl1vilg?f=videos&app=youtube_gdata", "type"=>"application/x-shockwave-flash", "medium"=>"video", "isDefault"=>"true", "expression"=>"full", "duration"=>"247", "yt:format"=>"5"}, {"url"=>"rtsp://v6.cache1.c.youtube.com/CiILENy73wIaGQlYim9dBkOLjhMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"247", "yt:format"=>"1"}, {"url"=>"rtsp://v6.cache1.c.youtube.com/CiILENy73wIaGQlYim9dBkOLjhMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", "type"=>"video/3gpp", "medium"=>"video", "expression"=>"full", "duration"=>"247", "yt:format"=>"6"}], "description"=>"jakefyfe.tumblr.com watch in high quality. \"so long, lonesome\" i didn't realize until now how many videos were already on youtube for this song. im going to leave it up anyway.", "keywords"=>"explosions, in, the, sky, so, long, lonesome, eits, indie, rock, instrumental, austin, texas, music, video, solar, system", "player"=>{"url"=>"http://www.youtube.com/watch?v=jotDBl1vilg&feature=youtube_gdata_player"}, "restriction"=>"AU NZ","thumbnail"=>[{"url"=>"http://i.ytimg.com/vi/jotDBl1vilg/0.jpg", "height"=>"240", "width"=>"320", "time"=>"00:02:03.500"}, {"url"=>"http://i.ytimg.com/vi/jotDBl1vilg/1.jpg", "height"=>"90", "width"=>"120", "time"=>"00:01:01.750"}, {"url"=>"http://i.ytimg.com/vi/jotDBl1vilg/2.jpg", "height"=>"90", "width"=>"120", "time"=>"00:02:03.500"}, {"url"=>"http://i.ytimg.com/vi/jotDBl1vilg/3.jpg", "height"=>"90", "width"=>"120", "time"=>"00:03:05.250"}], "title"=>"explosions in the sky - \"so long, lonesome\"", "duration"=>{"seconds"=>"247"}}, "rating"=>{"average"=>"4.962766", "max"=>"5", "min"=>"1", "numRaters"=>"188", "rel"=>"http://schemas.google.com/g/2005#overall"}, "statistics"=>{"favoriteCount"=>"450", "viewCount"=>"57066"}}

What in that result will indicate that the video cannot be played?


I think you want to be looking for a "media:restriction" field.

For example try this:

http://gdata.youtube.com/feeds/api/videos/jotDBl1vilg?fields=media:group/media:restriction&alt=json


With youtube api v3 the videoLicense field has three possible parameters, please use one of these:

videoLicense=any
videoLicense=creativeCommon
videoLicense=youtube

Thats a start to get an idea of if you can play it in youtube. If you are using that outside of youtube try using the videoSyndicated query.

videoSyndicated=true

Allows you to search for videos that can be played outside of youtube, say in a mobile app that uses youtube.

Please have a look at the reference for more information: YouTube V3 search.list reference

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号