YouTube downloader

Skapad 3 år sedan, skriven i Perl, med 335 visningar.
URL http://kod.perl.se/view/d24e01dc Bädda in
Ladda hem koden eller visa koden i råformatVisa bredare version
  1. #!/usr/bin/perl
  2. use WWW::Mechanize;
  3. use warnings;
  4. # ============================
  5. # This script takes a youtube
  6. # URL and converts it into an
  7. # aac audio file using ffmpeg
  8. # and youtube-dl.
  9. # The system must have ffmpeg,
  10. # WWW::Mechanize and
  11. # youtube-dl installed, as
  12. # well as an aac encoder for
  13. # ffmpeg. Simply change the
  14. # audio format to avoid
  15. # installing the aac encoder
  16. # ============================
  17. # by candyapplecorn
  18. # ============================
  19.  
  20. # declare a WWW::Mechanize object named $mech
  21. my $mech = WWW::Mechanize->new( autocheck => 1 );
  22.  
  23. # tell mech to get all html from a link or die
  24. die "Usage: \$ perl script URL\n" unless ( $ARGV[0] );
  25. $mech->get( $ARGV[0] );
  26.  
  27. # extract the title from the mech's content
  28. my @eowtitle = grep{ /.*/ }$mech->content ;
  29. my $string;
  30. foreach( split ("\n", $eowtitle[$#eowtitle]) ){
  31.     $string = $_ if $_ =~ /eow-title/;
  32.     last if $_ =~ /eow-title/;
  33. }
  34. $string =~ /title="(.*?)">/;
  35.  
  36. # create a system call
  37. my $systemCall = 'youtube-dl -o "'.$1.'.aac" --audio-format aac -x '.$ARGV[0].' &';
  38.  
  39. # pipe the system call's output to FH
  40. open(FH, "-|", $systemCall);
  41.  
  42. # print the output to the screen
  43. while(<FH>){ print $_ }

Svara på "YouTube downloader"

Här kan du skriva ett svar till kodsnutten ovan