Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the embed HTML code for a video hosted in youtube programmatically

How to get the embed HTML code for a video hosted in youtube programmatically. What Java API is available

like image 418
Jason Avatar asked Jan 28 '11 05:01

Jason


People also ask

How do I find the embed code?

Advanced users: Pressing F3 will also show you the source code. In Chrome, the short-key for Inspect is CTRL+SHIFT+I.

How do I get an embed code from a video online?

You can find the embed code by going to the YouTube play page, clicking "Share" and then "Embed." You can then copy the embed code, as well as customize a few options.


2 Answers

Use the YouTube Data API (there's pre-built GData client libraries, or you can do the HTTP/XML stuff yourself).

One of the <media:content/> entries will contain a URL for the embeddable SWF, if the video is embeddable.

like image 91
ephemient Avatar answered Nov 15 '22 15:11

ephemient


Assuming you have the URL of the video, it's fairly simple to generate one. You need the end of the URL (the part after the /watch?v=, let's call it ID). To generate the iframe embed html, just place it in the appropriate place (in the src attribute, don't include the brackets):

<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640"
height="390" src="http://www.youtube.com/embed/{ID}" frameborder="0"
allowFullScreen></iframe>

There are a couple of ways to get the v parameter from the URL. A regular expression would work.

like image 24
probabilityzero Avatar answered Nov 15 '22 15:11

probabilityzero