I’m trying to take a given URL entered by user and determine if the URL is pointing to a image or a video.
Example use case:
When a user paste in the URL of a YouTube video, on save the page will auto display the embedded YouTube player.
When a user posts URL of a picture in Flickr, on save, the page will auto display a smaller version of the Flickr image.
You can fetch the URL and see Content-type from the response.
You can use the HTTP Client from apache, it helps you to fetch the content of the URL and you can use it to navigate the redirects. For instance try to fetch the following:
http://www.youtube.com/watch?v=d4LkTstvUL4
Will return an HTML containing the video. After a while you’ll find out the video is here:
http://www.youtube.com/v/d4LkTstvUL4
But if you fetch that page you will get a redirect:
So, what you have to do is to fetch the URL and examine it, until you get final content
This section explains how to handle the redirects.