[Perl] Youtube playlist ripper

10/25/2013 20:20 f00lish#1
Youtube Playlist Ripper

This is probably something easy to create but you dont find it easily on the web.
I always wanted to download playlists from youtube cause I have slow internet connection and when I play pvps I get lag. So.. I decided to create something to help me and share it with you, cause you might have same problem and if you like it , improve the script for more.

Its written in perl so you will need to download perl if you plan to run it on windows.
[Only registered and activated users can see links. Click Here To Register...]

PHP Code:

#!perl
eval unpack u=>q{_=7-E('-T<FEC=#L*=7-E('=A<FYI;F=S.PIU<V4@0W=D.PIU<V4@5U=7.CI9;W54=6)E.CI$;W=N;&]A9#L*_=7-E($Q74#HZ57-E<D%G96YT.PIP<FEN="`B7'1Y;W5T=6)E('!L87EL:7-T(')I<'!E<B`O(&8P,&QI<V@@?7$!E;&ET97!V<&5R<UQN(CL*8VQO<V4@4U1$15)2.P};

open FH"<playlist.txt" || die $!;
my $lista = <FH>;
$lista =~ s/\n//g;
my $saf LWP::UserAgent->new();
my $data $saf->get($lista);
my $html $data->content;
my $path getcwd;
$path =~ s/\//\\/g;
$path .= '\\';
mkdir($ARGV[0]);
my $c;
if (
$html =~ /watch7-playlist-length">(\d*)</gs) {
    
$c = $1;
}

for (1..
$c) {
    if(
$html =~ /data-video-id="(.*?)"/gs) {
        eval { ytdownload($1,
$_) }
    }
}

sub ytdownload {
    my 
$client = WWW::YouTube::Download->new;
    my 
$title = $client->get_title($_[0]);
    
    print sprintf ("
%02d:%02d:%02d",reverse((localtime(time))[0..2])).":GET:::[$_[1]/$c$title\n";
    
$client->download($_[0],{
        fmt      => 
$client->get_fmt($_[0]),
        filename => 
$ARGV[0]."\\".$title.'.'.$client->get_suffix($_[0])  
        } 
    ) if ! -e 
$ARGV[0]."\\".$client->get_title($_[0]).'.'.$client->get_suffix($_[0]);
    #vid2mp3(
$path.$ARGV[0]."\\".$client->get_title($_[0]).'.'.$client->get_suffix($_[0]),$path.$ARGV[0]."\\".$client->get_title($_[0]).'.mp3')

Usage
  • Save the source code in a perl file such as playlist.pl
  • Run cmd.exe and navigate to the file path
  • Create a text file playlist.txt open and type the playlist link you want to download
  • run the script using: perl playlist.pl music (music is the folder we save the music)


The script is in a very basic step so improvements are to come!