curl-and-python

Re: Another pycurl example?

From: nixscripter <nixscripter_at_gmail.com>
Date: Tue, 02 Sep 2008 10:49:45 -0500

Alright, here it is folks. It's still a little rough around the edges,
so I am calling it beta.

Permit me to do a bit of explanation as to how it works. If you know
more about this stuff than I do, I would like your insights, since this
script might be hard to fix if YouTube should change their structure.

YouTube organizes their stuff with referrals. When you watch a video,
your browser downloads a video player, using a referral from the main
URL. This referral downloads a player which knows what video to access
and where it is using a temporary "cookie", which I call a "t-string"
(since it is a GET request parameter called "t"). The player then
accesses the video, using this t-string, at a different URL.

So, this script:

1. Sends an HTTP request for the player for a specific video.
2. Gets the referral to the player. Rather than following it, parses out
the t-string and other parameters the player would use.
3. Sends a second HTTP request for the video directly, using the parsed
information and knowledge of where to get the video.
4. Gets the video data as an FLV stream and saves it (writing to a file
in standalone mode, or down a file handle if used as a module).

This should be simple enough. Hopefully I have commented the code well
enough that it will be clear, but the way I organized it (methods and
classes must be declared before use) is somewhat out of order for a
logical flow. This is a note of clarification in case that's confusing.

Please send any comments, suggestions, and improvements. In particular,
errors like videos requiring login or have disappeared are not handled
well (i.e. the libcurl exception from the HTTP error code is thrown all
the way up the call stack).

Thanks for your interest.

--
Signed,
Dan Harrison (a.k.a. nixscripter)


_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python

Received on 2008-09-02