How can I use java to download a video file from http url(video streaming link)?

29,338

Solution 1

(Disclaimer: I'm the author of Resty).

Here is a code-example on how to download a google map image straight to disk:

Resty r = new Resty();
File f = r.bytes("http://maps.google.com/maps/api/staticmap?size=512x512" +
  "&maptype=hybrid&markers=size:mid%7Ccolor:red%7C37.815649,-122.477646&sensor=false").
  save(File.createTempFile("google", ".png"));

Solution 2

You will mostly have to consider the following cases:

Youtube

There are a few tools already available that are able to generate a link to the raw source file of a youtube video (which you can download, for example, as an h.264 coded .mp4 file) Try to find some of those, for example Userscripts, they will have plenty of source code that you can reuse to find out the URL. Here's an example. Maybe there are also some questions about this on Stackoverflow, I haven't looked. That's your job.

Flash Video

Websites that embed flash video use a flash player (duh) that is fed by some options, mostly it's hardcoded or JavaScript. This means that somewhere in the source code of the website, there is a link to a video file, probably an .mp4 or .flv file.

You will have to find that link (it could however be encrypted, URL-escaped, wrapped in JSON, whatever) and then download the raw file.

Example: This website feeds its flash player from a JSON string somewhere within the source code. I was able to decode it and generate a website that allows you to download the raw videos. In PHP, this worked like so.

Raw Files

Some URLs expose the file, like http://www.test.com/video.mp4. To save such a file from an URL, it comes down to just "downloading" it. There are plenty of tutorials, including this one.

Conclusion

It's not such an easy task to program a video downloading app that will work on all sites. Focus on "easy" ones such as Youtube and those websites where you can extract the file directly.

Share:
29,338
Tokendra Kumar Sahu
Author by

Tokendra Kumar Sahu

I am passionate about programming.

Updated on December 12, 2020

Comments

  • Tokendra Kumar Sahu
    Tokendra Kumar Sahu over 3 years

    Possible Duplicate:
    how to get video link from of live streaming videos using java?

    Hello all!

    I have to develop an application to download any video file from http url (video stream) to local system. Is there any free api for this. also there are some sites like youtube. Here no direct links available for video file. In such cases how can I get the exact video file link. Also I need java source to save video file from url.

    Thanks!