NoMoreNicksLeft

Filmmaker IQ video downloader

Jul 15th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.83 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. use WWW::Mechanize;
  5. use Date::Parse;
  6. use DateTime;
  7. use File::Path;
  8. use HTML::Grabber;
  9. use JSON::XS;
  10. use Data::Dumper;
  11.  
  12. ########################################################################################################################
  13. #                Change only the configuration settings in this section, nothing above or below it.                    #
  14. ########################################################################################################################
  15.  
  16. # Enclose value in double quotes, folders with spaces in the name are ok.
  17. my $root_folder = "/Users/john/Desktop";
  18.  
  19. ########################################################################################################################
  20. ########################################################################################################################
  21.  
  22. # Suddenly web robot.
  23. my $mech = WWW::Mechanize->new();
  24. $mech->agent_alias('Mac Safari');
  25.  
  26. # First we have to log in.
  27. $mech->get("https://vimeo.com/filmmakeriq/videos");
  28.  
  29. my $dom = HTML::Grabber->new(html => $mech->content);
  30.  
  31. my $z = 44;
  32.  
  33. while ($z > 0) {
  34.  
  35.     $dom->find('li[id^="clip"] a')->each(sub {
  36.         my $el = $_;
  37.         print $el->attr('title') . "\n";
  38.  
  39.         # Let's go to the video page.
  40.         my $mech2 = $mech->clone();
  41.         $mech2->get($el->attr('href'));
  42.  
  43.         my $dom2 = HTML::Grabber->new(html => $mech2->content);
  44.         # Looks like this finds the image, even as a jpeg
  45.         $dom2->find('noscript img')->each(sub {
  46.             my $pic = $mech2->clone();
  47.             my $piclink = $_->attr('src');
  48.             $piclink =~ s/(.+)\?.+$/$1/;
  49.             $z--;
  50.             #$pic->get($piclink, ':content_file' => "$root_folder/ep$z.jpg");
  51.         });
  52.  
  53.         # Holy shitsnacks, the link to the actual video was hiding here all along.
  54.         $dom2->find('div.wrap_content script:first-child')->each(sub {
  55.             my $mech3 = $mech2->clone();
  56.             my $mp4link = $_->text;
  57.             $mp4link =~ s/.+e.open\("GET","(https.+?)".+$/$1/;
  58.             $mech3->get($mp4link);
  59.  
  60.             my $json = JSON::XS->new->utf8->decode($mech3->content());
  61.             my @qualtiies;
  62.             my $progressive = $json->{'request'}->{'files'}->{'progressive'};
  63.             foreach my $q (@$progressive) {
  64.                 if ($q->{'width'} == 1280) {
  65.                     $mech3->get($q->{'url'}, ':content_file' => "$root_folder/ep$z.mp4");
  66.                     system("/usr/local/bin/ffmpeg -i ep$z.mp4 -c copy -map_metadata -1 -map_chapters -1 -metadata:s:a:0 language=eng " .
  67.                            "\"Filmmaker IQ - S01E$z - " . $el->attr('title') . ".mp4\"");
  68.  
  69.                 }
  70.             }
  71.         });
  72.     });
  73.     $mech->follow_link(text => "Next");
  74.     $dom = HTML::Grabber->new(html => $mech->content);
  75. }
Add Comment
Please, Sign In to add comment