How do I get a YouTube FLV URL?
Solution 1
As mentioned in other posts, you may want to look at our code in youtube-dl (or in the code of the Firefox extension called FlashVideoReplacer).
In the particular case of youtube-dl, the "real work" is done in the
subclasses of InformationExtractor
and it hard to give a "stable" answer,
as the layout of such sites changes constantly.
There are some pieces of the information that are not dynamic, such as, for instance, the uploader of the video, the title, the date of upload, and, most importantly, the identifier of the video (a 11-character string).
For the dynamic parts, what can be said about such tools is that, essentially, the URLs generated by such videos are dynamically generated and you need to perform some back-and-forth communication with the server.
It is important to have in mind that what such sites can (and do) take into consideration depend on a number of parameters, including: the cookies that you have already received---as the case for HTML5 videos, your geolocation---for regional control, your age--for "strong" material, your language/locale---for showing content tailored to you, etc.
youtube-dl uses a regular expression to extract the video ID from the URL that you give and, then, uses a "normalized", typical URL as used from the United States, from which to proceed.
Some of the dynamic data to be gathered includes:
- some time-stamp (the
expire
, andfexp
parts of the final URL) - the cookies sent to the browser
- the format in which we want to download the video (the
itag
part of the final URL) - throttling information (the
algorithm
,burst
,factor
) - some hashes/tokens used internally by them (e.g., the
signature
part of the final URL)
Some of the information listed above were once not required, but now they are (in particular, the cookies that they send you). This means that the information listed above is very likely to become obsolete, as the controls become stricter.
You can see some of the work (with respect to the cookies) that I did in this regard in the implementation of an external backend to use an external downloader (a "download accelerator") with what youtube-dl extracts.
Discloser: I have committed some changes to the repository, and I maintain
the youtube-dl
package in Debian (and, as a side effect, in Ubuntu).
Solution 2
You might want to take a look at how youtube-dl downloads the files. As YouTube changes, that program does seem to get updated rather quickly.
Solution 3
Youtube doesn't store FLV files, they compile your video into a SWF object. Those videos need to be either extracted or converted to FLV in order to get the FLV.
http://www.youtube.com/v/videoid
ex:
http://www.youtube.com/watch?v=C6nRb45I3e4
becomes
http://www.youtube.com/v/C6nRb45I3e4
From there, you need to convert the SWF into an flv, which can be done with ffmpeg.
Related videos on Youtube
xLite
Updated on June 04, 2022Comments
-
xLite almost 2 years
Looking through the site, every question uses an outdated method. How do the YouTube FLV downloader websites/applications do it?
I am trying to do this in PHP but the theory or steps to do it will suffice, thanks.
-
AndyDunn about 12 yearsNice work with youtube-dl, its nice to find something useful like that which is easy to use and actively maintained.
-
rbrito about 12 years@AndyDunn, youtube-dl has gained support for many other sites since I wrote that answer and the newest changes. Seeing one of the simpler
InformationExtractors
is a good way of understanding how the principles of scraping for the videos work. -
AndyDunn about 12 yearsthanks a bunch for pointing that out. That makes a massive difference to what I'm doing, knowing that it can also work for the other websites too ! :)
-
Admin about 9 years@rbrito I have a tip: use the host
http://www.youtube-nocookie.com
to avoid cookie validation, localStorage mandatory id and JavaScript encryption with cookie being mandatory for signature and id. essentially an 'incognito mode' also, in additional I'm sending in the PHP the headerDNT: 1
and the server should respect that avoiding tracking the user-session by IP.