How can I get the correct url to the video file from an embedded video?

29,134

If your using jsoup you can get the url quite easily. Just use jsoup to select all the possible video tags (<iframe>, <videos>, <embed>, etc). Then get the src attribute and store that where you want it:

Example

//Standard Jsoup search
Elements iframes = body.select("iframe");

/*Gets the src of all the iframes or other tag, and if you have
multiple videos you might have to do this in a for loop.*/    
String videoURL = iframes.attr("src");
Share:
29,134
Writwick
Author by

Writwick

Starting to Code...

Updated on February 22, 2020

Comments

  • Writwick
    Writwick about 4 years

    I want to get the actual Video File Url from an embedded video on any website. It essentially is not YouTube. It can be any website. I am coding for android on Java.

    For Example : The thing I want to do is same as this IDM button does :

    IDM "Download this video" Button

    [Actually not the same because the button there captures a network stream when it gets started by the player. But I want to get the file straight from the player.] Is there a way to attain this? Can Any external Library [e.g. Jsoup] do this?

    I am already using Jsoup to get some other contents of the page but I have no idea how to do this.

  • Writwick
    Writwick almost 11 years
    As you may have seen I am trying to do this on android. There is no IE. Plus there is no flash support in 4.1+ androids. So I cannot always play the video to capture the stream. If you do a bit research with chrome developer tools, You can see that a new stream opens up when the play button is clicked. From there an URL to the streaming file can be got without any hassle. But in no way I can play the video in the android browser or webview dynamically, at least I can't think of any way. And of flash, it isn't supported in 4.0+. So I have to get another way round...
  • Writwick
    Writwick almost 11 years
    I don't think the src field contains the direct URL to the video file. If it did contain, I wouldn't have posted this question here! I have thoroughly checked up the html code of the site (and decided to use jsoup to parse it to get info) but I could not find the URL in the source. Even I bet it can't contain the direct URL. Most probably It contains the link to the page where the video is embedded so that it can display the contents of the page within the iframe or the similar tags.....