Download website file with perl one liner
This time I'll use Perl programming language which is my favorite language at the moment and write a one-liner which downloads a YouTube video. Instead of parsing the YouTube video page, let's look how an embedded YouTube video player on a 3rd party website gets the video. Let's go to this cool video and look at the embed html code:. So far we have no information how the flash player will retrieve the video, the only thing we know that 'iurl' stands for 'image url' and is the location of the thumbnail image.
Let's sniff the traffic again, this time with an excellent Internet Explorer plugin ' HttpWatch Professional'. This is exactly what what we saw in the previous article on downloading videos with gawk!
Get Ahead by Going Headless. Achieving a true 3-Tiered Architecture through Load Balancing. Online Marketing. How to get more followers on Twitter. Number of combinations of the arrangement of caps. How to make game bots for chat rooms? Doubly Linked List - An Overview. Prime numbers. Follow us! Get the Latest Bytes Updates.
By using this site, you agree to our Privacy Policy and Terms of Use. The shebang line your server requires might be different. Most web hosts will have that information posted on their site somewhere.
In the interest of good perl coding practices and CGI security we are going to add a switch to the shebang line: -T. Note: it must be an uppercase T. Expand Select Wrap Line Numbers! This is really to prevent you, as the programmer of the script, from making a terrible mistake and allowing the users of your CGI form to send data to the server that can be used in an insecure way.
Modules Modules are sort of like separate perl programs you can use in your perl program. Many people have written modules that have become standards that other perl programmers use all the time. They affect the way perl itself functions. The "CGI" module is the module that will do most of the work for us: Process form data, print http headers, and more.
The "CGI::Carp" module is really for debugging and may help you to get your script running if you have problems. If there are any fatal errors that cause the script to fail, it will print an error message to the screen. These are the same errors that will be printed in the server error log too. I have set this limit low 1 kb because this script will need little data sent to it to work.
The second line tells the script to not accept file uploads. Makes sense since we want to download files, not upload them. This prevents users from attempting to use an altered form to send files to your script. Probably best to raise this as a new question. Using File::Fetch under Linux 4. The LWP::Simple approach described in stackoverflow. If downloading that file is all you actually do, you'd better go with davorg's answer. Tomasz Tomasz 4, 8 8 gold badges 53 53 silver badges 61 61 bronze badges.
DimiDak DimiDak 3, 1 1 gold badge 21 21 silver badges 24 24 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. The following is just an example of how to do this, when you have permission. Simply open the command line and type the program name with the URL or video id of the video to download. For example:. Read on for the one liner example.
This one liner is simple. We then initiate a WWW::YouTube::Download object with new, and immediately call the download method on the new object. For example with this URL:.
0コメント