Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- $ENV{PATH} = "/bin:/usr/bin:/usr/local/bin:/opt/local/bin";
- my $prefix = "";
- my $retry = 1;
- my $retryCounter = 0;
- my $user_url = "";
- my $user_prefix = "";
- my $resolution = "itag=22";
- chomp($user_url = $ARGV[0]);
- my $url = "$1" if ($user_url =~ m/^([a-zA-Z0-9\_\-\&\?\=\:\.\/]+)$/ or die "\nError: Illegal characters in YouTube URL\n\n" );
- my $html = `curl -sS -L --compressed -A "Mozilla/5.0 (compatible)" "$url"` or die "\nThere was a problem downloading the HTML page.\n\n";
- my ($title) = $html =~ m/<title>(.+)<\/title>/si;
- $title = lc ($title);
- $title =~ s/_youtube//ig;
- $title =~ s/^_//ig;
- $title =~ s/_amp//ig;
- $title =~ s/_39_s/s/ig;
- $title =~ s/_quot//ig;
- my ($download) = $html =~ /"url_encoded_fmt_stream_map"(.*)/ig;
- my @urls = split(',', $download);
- OUTERLOOP:
- foreach my $val (@urls) {
- if ( $val =~ /mp4/ ) {
- my @res = split(',', $resolution);
- foreach my $ress (@res) {
- if ( $val =~ /$ress/ ) {
- $download = $val;
- last OUTERLOOP;
- }
- }
- }
- }
- $download =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
- $download =~ s/sig=/signature=/g;
- $download =~ s/\\u0026/\&/g;
- $download =~ s/(type=[^&]+)//g;
- $download =~ s/(fallback_host=[^&]+)//g;
- $download =~ s/(quality=[^&]+)//g;
- $download =~ s/&+/&/g;
- $download =~ s/&$//g;
- $download =~ s/%2C/,/g;
- $download =~ s/%252F/\//g;
- $download =~ s/^:"url=//g;
- $download =~ s/\"//g;
- $download =~ s/\?itag=22&/\?/;
- my $counter1 = () = $download =~ /&itag=\d{2,3}/g;
- if($counter1 > 1){ $download =~ s/&itag=\d{2,3}//; }
- if($counter1 == 0){ $download .= '&itag=22' }
- my ($youtubeurl) = $download =~ /(https?:.+)/;
- print "$youtubeurl\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement