Advertisement
Tukan3

Perl-Skript for getting Youtube-URL

Apr 26th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.68 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. $ENV{PATH} = "/bin:/usr/bin:/usr/local/bin:/opt/local/bin";
  5. my $prefix = "";
  6. my $retry = 1;
  7. my $retryCounter = 0;
  8. my $user_url = "";
  9. my $user_prefix = "";
  10. my $resolution = "itag=22";
  11.  
  12. chomp($user_url = $ARGV[0]);
  13. my $url = "$1" if ($user_url =~ m/^([a-zA-Z0-9\_\-\&\?\=\:\.\/]+)$/ or die "\nError: Illegal characters in YouTube URL\n\n" );
  14. my $html = `curl -sS -L --compressed -A "Mozilla/5.0 (compatible)" "$url"`  or die  "\nThere was a problem downloading the HTML page.\n\n";
  15. my ($title) = $html =~ m/<title>(.+)<\/title>/si;
  16. $title = lc ($title);
  17. $title =~ s/_youtube//ig;
  18. $title =~ s/^_//ig;
  19. $title =~ s/_amp//ig;
  20. $title =~ s/_39_s/s/ig;
  21. $title =~ s/_quot//ig;
  22. my ($download) = $html =~ /"url_encoded_fmt_stream_map"(.*)/ig;
  23. my @urls = split(',', $download);
  24. OUTERLOOP:
  25. foreach my $val (@urls) {
  26.     if ( $val =~ /mp4/ ) {
  27.        my @res = split(',', $resolution);
  28.        foreach my $ress (@res) {
  29.          if ( $val =~ /$ress/ ) {
  30.          $download = $val;
  31.          last OUTERLOOP;
  32.          }
  33.        }
  34.     }
  35. }
  36. $download =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
  37. $download =~ s/sig=/signature=/g;
  38. $download =~ s/\\u0026/\&/g;
  39. $download =~ s/(type=[^&]+)//g;
  40. $download =~ s/(fallback_host=[^&]+)//g;
  41. $download =~ s/(quality=[^&]+)//g;
  42. $download =~ s/&+/&/g;
  43. $download =~ s/&$//g;
  44. $download =~ s/%2C/,/g;
  45. $download =~ s/%252F/\//g;
  46. $download =~ s/^:"url=//g;
  47. $download =~ s/\"//g;
  48. $download =~ s/\?itag=22&/\?/;
  49. my $counter1 = () = $download =~ /&itag=\d{2,3}/g;
  50. if($counter1 > 1){ $download =~ s/&itag=\d{2,3}//; }
  51. if($counter1 == 0){ $download .= '&itag=22' }
  52.  
  53. my ($youtubeurl) = $download =~ /(https?:.+)/;
  54. print "$youtubeurl\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement