0

How to display properly a shortened URL which can hold either video or image file? The URL does not contain extension and the domain can be of different origin. I need to use either video or image tag depending on the source type so it is rendered correctly by browser. The solution can be with JavaScript or markup.

Example:
[IMAGE] http://bit.ly/1uI7Ddj
[VIDEO] http://bit.ly/1vvkYJ1

I tried following but it doesn't work as expected:

<video width="300" height="150" src="http://bit.ly/1uI7Ddj">
    <img width="300" height="150" src="http://bit.ly/1uI7Ddj" alt="Fallback if video is not playing" />
</video>
Mariusz Miesiak
  • 638
  • 1
  • 6
  • 19
  • possible duplicate of [Determine Final Destination of a Shortened URL in PHP?](http://stackoverflow.com/questions/1319621/determine-final-destination-of-a-shortened-url-in-php) – skobaljic Nov 22 '14 at 01:18
  • @skobaljic, I've added tags for HTML5 and JavaScript. I'm not interesed in PHP solution. – Mariusz Miesiak Nov 24 '14 at 09:53
  • I see, and when I spend half an hour to help you, you do not even read the answer. – skobaljic Nov 25 '14 at 20:47

2 Answers2

0

That is not possible unless you own the domain where you want the shortened URL. For example, to do that, you would need to own (or have access to) the website bit.ly.

bit.ly is not hosting your video or your image, it only redirects them to the real URL when you click on the link.

The source code from your bit.ly can be found here on chrome: view-source:http://bit.ly/1uI7Ddj

You will see that your image is NOT in the code. It only redirects to the page that DOES contain your image.

Ian Hazzard
  • 7,661
  • 7
  • 34
  • 60
0

To get full URL on bit.ly, you need to register to developers API and create an app, than you can use expand method.

For goo.gl short links, sing in with Google account and register to API, and use expand method.

But best in your case would be longurl.org API, which has a simple method to expand URLs. Take a look at their expand-url documentation.

An example request to their API:

GET http://api.longurl.org/v2/services&format=json

and since you do not want to use PHP, than you need to ask for jsonp format this way:

GET http://api.longurl.org/v2/services&format=json&callback=foo&user-agent=Application-Name%2F3.7

So, alltogether, you need to expand url and get json this way:

GET http://api.longurl.org/v2/expand?url=http%3A%2F%2Fbit.ly%2F1uI7Ddj&format=json&callback=foo&user-agent=Application-Name%2F3.7

You get response:

foo({"long-url":"http:\/\/flark.it\/f\/i\/1884680242.WP_000008.jpg"})

Similar with jsonp, read more about jsonp

There is also expandURL API, but I do not see they offer jsonp responses. Example there would be:

GET http://expandurl.appspot.com/expand?url=http%3A%2F%2Fbit.ly%2F1uI7Ddj

and you get json response:

{
    "status": "OK",
    "end_url": "http://flark.it/f/i/1884680242.WP_000008.jpg",
    "redirects": 1,
    "urls": ["http://bit.ly/1uI7Ddj",
    "http://flark.it/f/i/1884680242.WP_000008.jpg"],
    "start_url": "http://bit.ly/1uI7Ddj"
}
Community
  • 1
  • 1
skobaljic
  • 9,379
  • 1
  • 25
  • 51