Tom Lehman
Tom Lehman

Reputation: 89373

Determine whether a YouTube video cannot be embedded in a specific site

This YouTube video can be embedded into most sites (e.g., Stackoverflow), but it cannot be embedded into Rap Genius. You can try it yourself by pasting the embed code in to Rap Genius with firebug. You'll see this:

I need a way to detect whether a video is specifically blocked from Rap Genius.

Note that this is different from checking whether a video cannot be embedded anywhere – i.e., if you GET http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=_kmeFXjjGfk, you'll see that in the JSON response, data.items[0].accessControl.embed == 'allowed'

One clue: before the video starts playing, the player makes a request to a URL that looks like this:

http://www.youtube.com/get_video_info?video_id=_kmeFXjjGfk&el=embedded&ps=default&eurl=http%3A%2F%2Frapgenius%2Ecom&hl=en_US

Which, when curled, gives this response:

status=fail&errorcode=150&reason=This+video+contains+content+from+UMG%2C+who+has+blocked+it+from+display+on+this+website.%3Cbr%2F%3E%3Cu%3E%3Ca+href%3D%27http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_kmeFXjjGfk%26feature%3Dplayer_embedded%27+target%3D%27_blank%27%3EWatch+on+YouTube%3C%2Fa%3E%3C%2Fu%3E&fslarge=1

So maybe I can just query this URL? Will this work in all cases? Is there an "official" way of doing this?

Upvotes: 2

Views: 5774

Answers (2)

Laurent Pierre
Laurent Pierre

Reputation: 9

You have all the info in http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=_kmeFXjjGfk

"status":{"value":"restricted","reason":"limitedSyndication"},"restrictions":[{"type":"country","relationship":"deny","countries":"DE"}]

March 19, 2013 -- Response is now quite different than that given above:

{"apiVersion":"2.1","data":{"updated":"2013-03-19T14:47:14.533Z","totalItems":0,"startIndex":1,"itemsPerPage":25}}

Upvotes: 0

FredL
FredL

Reputation: 1045

I had the error:

This video contains content from XXX

I noticed I was using https when requesting the page containing the embedded video. Switching back to http seems to have fixed the problem.

Upvotes: 1

Related Questions