0

Youtube allows videos to be embeded using the link of kind

https://www.youtube.com/embed/uniqueId, which can be used to plugin the video into your website.

If we try to use the link of the kind https://youtu.be/uniqueId youtube thorws up an error like the one addressed in this question

This approach even though not possible using <iframe> tag, it must be theoretically possible to render any public content on the webpage as that link can be accessed by all.

Is it possible to open a tag inside html which runs some kind of browser sandbox and just renders the video element of the original Youtube page, which is funcitonally equivalent to an embed video.

This seems like a theoretical possibility, can we do it?

Profile name
  • 153
  • 7

1 Answers1

1

The problem is that YouTube (or any website, really) knows if you try to embed it. This way, it most probably will not let you do that.

If you have a URL of type https://youtu.be/uniqueId - the easiest & the most practical way is to parse uniqueId out of that URL, use the uniqueId part to construct the embed URL & then use it to embed the video via iframe tag.

Keep in mind that YouTube doesn't allow to embed any video, only some of them. Even though it's the best one can do without violating terms of YouTube, I believe.

Igor Bykov
  • 2,532
  • 3
  • 11
  • 19
  • Yes but that is not the question. If I'm able to run YouTube in a browser sandbox inside a webpage, YouTube has no way of stopping me. – Profile name Jan 30 '22 at 03:27
  • 2
    If you refer to the fact that you can see video in your browser while on youtube.com - yes, everyone can. Now if the question is "how to make visitors of _my website_ see the same?" - the answer is above. There's no magical way to embed a page without embeding it. You can try to scrap YouTube from BE but it's illegal & not going to work anyways. – Igor Bykov Jan 30 '22 at 07:40
  • How about running a browser sandbox in your webpage? Also what's BE? – Profile name Jan 30 '22 at 08:40
  • IDK what you refer to with `sandbox`. I assume you mean something like opening another browser window inside the browser window with your site which is impossible (`iframe` is the closest to this, but it has some limitations as I've already mentioned). BE is an abbreviation for "backend". From the backend, you can request _any_ webpage or even pretend to be a real browser. However, even if you do - I don't think it's going to work in the case of YouTube because YouTube will actively protect itself from this trick. – Igor Bykov Jan 30 '22 at 09:05
  • 1
    I'm more concerned as to how YouTube knows what's happening on the client side. How does it know. As far as I onow, Youtube server will only see get requests from a particular ip. How does it know? – Profile name Jan 30 '22 at 11:06
  • 1
    Well, in the case of `iframe` there are mechanisms specifically designed for that, see [X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) for more info. In the case of BE-based scrapping - there is no 100% ideal way of protecting, but there are numerous tools available for that. Just google "web scraping protection" for more info, there are 6m+ results first 10 of which are ads of companies that offer some kind of protection. – Igor Bykov Jan 30 '22 at 12:13
  • Ya I just sent a GET request for youtube video link trough postman API client and I got 200 response with full html code. It seems to work. – Profile name Jan 30 '22 at 12:37
  • Oh, that's great, but, unfortunately, completely useless for any practical purpose. – Igor Bykov Jan 30 '22 at 13:01
  • But can't we get the video stream and play it in our website? That's what I want to know. – Profile name Jan 30 '22 at 14:21
  • Yes, that's what `iframe` is for – Igor Bykov Jan 30 '22 at 16:21
  • No you are missing the point, YouTube refuses connection with iframe. But Youtube gives proper 200 response when GET request is called from backend. It's different. I'm asking can we use this backend http get request and then stream the videos in our website. – Profile name Jan 30 '22 at 17:44