0

I want to know how to get the direct link to an embedded video (the link to the .flv/.mp4 or whatever file) from just the embed link.

For example, http://www.kumby.com/ano-hana-episode-1/ has

<embed src="http://www.4shared.com/embed/571660264/396a46be"></embed>

, though the link to the video seems to be "http://dc436.4shared.com/img/571660264/396a46be/dlink__2Fdownload_2FM2b0O5Rr_3Ftsid_3D20120514-093834-29c48ef9/preview.flv"

How does the browser know where to load the video from? How can I write code that converts the embed link to a direct link?

UPDATE: Thanks for the quick answer, Quentin. However, I don't seem to receive a 'Location' header when connecting to "http://www.4shared.com/embed/571660264/396a46be".

import urllib2
r=urllib2.urlopen('http://www.4shared.com/embed/571660264/396a46be')

gives me the following headers: 'content-length', 'via', 'x-cache', 'accept-ranges', 'server', 'x-cache-lookup', 'last-modified', 'connection', 'etag', 'date', 'content-type', 'x-jsl'

from urllib2 import Request
r=Request('http://www.4shared.com/embed/571660264/396a46be')

gives me no headers at all.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • You need to show some more code to demonstrate how you make the request. Most HTTP libraries will, by default, follow redirects automatically so won't tell you about the direct. – Quentin May 14 '12 at 10:38
  • @Quentin: So it's a python issue after all? Fine, I'll update the tags and the question. – Aran-Fey May 14 '12 at 10:42

1 Answers1

1

The server issues a 302 HTTP status code and a Location header.

$ curl -I http://www.4shared.com/embed/571660264/396a46be
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1

(snip cookies)

Location: http://static.4shared.com/flash/player/5.6/player.swf?file=http://dc436.4shared.com/img/M2b0O5Rr/gg_Ano_Hi_Mita_Hana_no_Namae_o.flv&provider=image&image=http://dc436.4shared.com/img/M2b0O5Rr/gg_Ano_Hi_Mita_Hana_no_Namae_o.flv&displayclick=link&link=http://www.4shared.com/video/M2b0O5Rr/gg_Ano_Hi_Mita_Hana_no_Namae_o.html&controlbar=none
Content-Length: 0
Date: Mon, 14 May 2012 10:01:59 GMT

See How do I prevent Python's urllib(2) from following a redirect if you want to get information about the redirect response instead of following the redirect automatically.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks a lot! No unnecessary information/text there! However, I'm not receiving a 'Location' header. I'm updating the question. – Aran-Fey May 14 '12 at 10:34
  • Actually, I guess I'm stupid for not having noticed until now, but there's no link to any video file. 'Location' links to the 4shared player, two video thumbnails and the 4shared website. – Aran-Fey May 14 '12 at 16:09