12

I am trying to have my client application filter out videos that do not allow embedding. My understanding here is that there is no way to limit the feed (i.e. format=5 is insufficient) to do this and that I must check the properties of the entry myself, for the <yt:accessControl> tag and the <app:control> and <yt:state> tags.

This isn't working for me.

For example, this video: https://www.youtube.com/watch?v=waxat-_tRH8

doesn't embed: https://www.youtube.com/embed/waxat-_tRH8

even though the API returned data indicates (as far as I can tell) that it should be able to embed: https://gdata.youtube.com/feeds/api/videos/waxat-_tRH8?v=2

The entry does not contain any <yt:noembed> tag (see prior question) and the <media:restriction type='country' relationship='deny'>ME DE RS</media:restriction> does not explain this since I am in the US (see prior question) (see prior question).

What am I missing here?

EDIT: The embed link above works in my web browser, but not in my client app's WebView....!?

Community
  • 1
  • 1
justin k.
  • 504
  • 1
  • 6
  • 15
  • https://dl.dropbox.com/u/6097787/test.html Works fine if you view it on Dropbox. Does _not_ work if you save it to disk and open it as a file. – justin k. Nov 15 '12 at 23:42

7 Answers7

9

Certain videos have a domain-level whitelist or blacklist applied to them. This is done at the discretion of the content owner.

If there is a whitelist or a blacklist, and the domain of the embedding site can't be determined (perhaps because of there not being a real referring domain in the case of your native application), then the default behavior is to block playback.

This blog post has a bit more detail as well: http://youtube-eng.blogspot.co.uk/2011/12/understanding-playback-restrictions_28.html

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167
  • 1
    Thanks Jeff. A few followups: 1. Is there anything I can do in order to be allowed to play these videos? 2. If not, is there any way to determine these restrictions through the API, before loading the embed? As it is, I have a very bad user experience due to presenting these non-playable videos. – justin k. Nov 20 '12 at 19:08
  • Unfortunately, no. That specific video can only be played when it's embedded on a real website with a real referring URL, due to the way domain white/blacklisting works. And no, we don't expose those lists via the API. It's a longstanding feature request, though. – Jeff Posnick Nov 20 '12 at 22:07
  • Jeff, is domain-level restriction accessible via API v3 now? any workarounds? – revo Jun 18 '15 at 14:06
  • I don't believe it's returned in the v3 API response, but I no longer work on the API and am not authoritative. – Jeff Posnick Jun 18 '15 at 14:09
  • hmm after 8years no solution, what about getting thumbnails from the stream? – Vincent Alex Feb 15 '20 at 19:54
9

As Jeff Posnick pointed out, some videos have blacklists. If you try and request a video with a blacklist from an app and not a web page, you will see this error message:

"This video contains content from ___. It is restricted from playback on certain sites."

It's likely your app is NOT blacklisted, and that you're being blacklisted incorrectly. To fix this, you need to supply your Youtube API request with an origin (as atulkhatri pointed out).

In your request header for the Youtube video, set Referer to the domain in which you intend to be making the call from, (for ex. the domain of your app's corresponding website). If you don't have a domain, you could easily write some other domain, and that might work too.

  • For Android (Java), you can see an example here.

  • For iOS, look above

  • For React Native, you can use the origin prop on the component to your domain (origin is mentioned in the docs but doesn't tell you much about it).

  • Here is another example of the same issue in a browser when an extension blocked the Referer header from being sent for good measure.

This answer works for the V3 API of Youtube.

Community
  • 1
  • 1
Jake
  • 990
  • 1
  • 10
  • 17
  • I tried embedding a video on my site (currently it's local so only accessible through IP), and I'm facing the same issue. How can I changet the Referrer in a browser. All I have is the iframe embed code. Thanks. – fractal5 Oct 23 '16 at 08:17
  • @fractal5 It's possible working locally may cause you this problem. You can also take a look at [this page](http://stackoverflow.com/questions/8468335/what-is-the-http-referer-if-the-link-is-clicked-in-an-iframe) to get more info and see whether your browser may be a part of the problem as well. – Jake Oct 25 '16 at 15:29
  • 1
    @JakeNelken Thanks for the attribution. Appreciate that. – atulkhatri May 19 '17 at 05:16
  • @JakeNelken I used this method to play embed restricted videos in my .NET application by adding the referer. Recently this stopped working. /embed videos don't play at all now, just show up as a black screen, no player is loading, so I thought it was a flash issue but /v/ links play just fine, but the restriction bypass doesn't work anymore. You had any experience with this? – Josh May 30 '17 at 14:05
  • @Josh The app I used this trick for seems to show videos just fine still. If you discover how to fix it on your end please let us know. I doubt you have been specifically blacklisted but that's also a possibility (which in that case would break your videos from only 1 source -- not all videos with blacklists). – Jake Jun 08 '17 at 14:15
  • 1
    @JakeNelken I fixed my issue. FEATURE_BROWSER_EMULATION was the ticket. https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx – Josh Jun 09 '17 at 20:18
  • @Jake Running locally was the cause in my case. Thanks for pointing that out. – AnB Apr 26 '23 at 00:06
6

Actually, if you embed your video here:

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default

Like this:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<iframe width="420" height="315" src="https://www.youtube.com/embed/waxat-_tRH8" frameborder="0" allowfullscreen></iframe>
</body>
</html>

It actually is playable. So the problem actually comes back to why it works on website but not iOS mobile app?

Then I found out about this post:

http://support.metacdn.com/hc/en-us/articles/204513985-Video-Player-Embed-Restriction

It explains that the embed could be restricted due to lack of HTTP header "Referer" field.

So after setting the refer field, this video will be playing in iOS app:

let youtubeURL = NSURL(string: "https://www.youtube.com/embed/YQHsXMglC9A?autoplay=1") 
let youtubeRequest = NSMutableURLRequest(URL: youtubeURL!) 
youtubeRequest.setValue("https://www.youtube.com", forHTTPHeaderField: "Referer") 
webView.loadRequest(youtubeRequest)

Wala, it works now!

Are you happy? cause I am happy. :)

RainCast
  • 4,134
  • 7
  • 33
  • 47
  • 1
    How can we do the same for android? I am using ionic framework iframe is working fine on browser but not on android. On android it simply show message 'Restricted from playback on certain sites' – user1188867 May 30 '16 at 07:50
  • Sorry @user1188867, I am not familiar with Android, you may try search with "how to modify HTTP Referer field in Android", it could be the same cause. – RainCast Jun 01 '16 at 00:03
  • still not working for some id, please can anyone confirm it is working for video id=5IJ14RAqz3s – Zuhair Hussain Oct 04 '16 at 19:13
  • 1
    @user1188867 please, have a look at my [answer](https://stackoverflow.com/a/46554638/4171098) – Mateusz Wlodarczyk Oct 03 '17 at 22:59
3

You can use this answer. This worked perfectly in my case-

Adding origin in player vars as https://www.youtube.com

See this answer

Community
  • 1
  • 1
atulkhatri
  • 10,896
  • 3
  • 53
  • 89
1

For those who experience the same issue in webView on Android. I fixed that by adding the referer header field similarly to what @RainCast did in her answer.

 Map<String, String> extraHeaders = new HashMap<>();
 extraHeaders.put("Referer", "http://youtube.com");
 String url = "https://www.youtube.com/embed/dQw4w9WgXcQ";

 webView.loadUrl(url, extraHeaders);

It works for pure URL, but I don't know how to pass those parameters while injecting iFrame in the webView.

0

Add player vars while initializing youtube sdk:

NSDictionary *playerVars = @{
                             @"origin" : @"http://www.youtube.com",
                             };
[self.playerView loadWithVideoId:@"videoid" playerVars:playerVars];

Enjoy!

Logic
  • 705
  • 1
  • 9
  • 27
-1

try like this instead

<iframe width="300" height="200" src="www.youtube.com/embed/<video-id>?enablejsapi=1" frameborder="0" allowfullscreen></iframe>