forked from sergiotarxz/Peertube-dl
Modularizado el código.
This commit is contained in:
parent
e74eafffd8
commit
beec75b418
4
MANIFEST
4
MANIFEST
@ -1,5 +1,9 @@
|
|||||||
|
AUTHORS
|
||||||
bin/peertube-dl
|
bin/peertube-dl
|
||||||
cpanfile
|
cpanfile
|
||||||
|
lib/Peertube/DL/Downloaders.pm
|
||||||
|
lib/Peertube/DL/UserAgent.pm
|
||||||
|
lib/Peertube/DL/Utils.pm
|
||||||
LICENSE
|
LICENSE
|
||||||
Makefile.PL
|
Makefile.PL
|
||||||
MANIFEST This list of files
|
MANIFEST This list of files
|
||||||
|
120
bin/peertube-dl
120
bin/peertube-dl
@ -5,18 +5,15 @@ use feature 'say';
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use LWP::UserAgent;
|
use Peertube::DL::UserAgent;
|
||||||
use URI::Encode;
|
use Peertube::DL::Downloaders;
|
||||||
use JSON;
|
|
||||||
|
|
||||||
use Data::Dumper;
|
my $ua = Peertube::DL::UserAgent->new( timeout => 10 );
|
||||||
|
|
||||||
my $ua = Peertube::UserAgent->new( timeout => 10 );
|
|
||||||
$ua->agent('Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0');
|
$ua->agent('Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0');
|
||||||
my $response = $ua->get( $ARGV[0] );
|
my $response = $ua->get( $ARGV[0] );
|
||||||
my %handlers = (
|
my %handlers = (
|
||||||
gocdn => { reg => qr/gocdn\.html#/, subr => \&Peertube::Downloaders::gocdn },
|
gocdn => { reg => qr/gocdn\.html#/, subr => \&Peertube::DL::Downloaders::gocdn },
|
||||||
animeid => { reg => qr/animeid\.to\/streaming\.php\?/, subr => \&Peertube::Downloaders::animeid },
|
animeid => { reg => qr/animeid\.to\/streaming\.php\?/, subr => \&Peertube::DL::Downloaders::animeid },
|
||||||
);
|
);
|
||||||
|
|
||||||
die "No url passed" unless @ARGV;
|
die "No url passed" unless @ARGV;
|
||||||
@ -28,115 +25,10 @@ for my $x ( keys %handlers ) {
|
|||||||
if ($@) {
|
if ($@) {
|
||||||
say $@;
|
say $@;
|
||||||
} else {
|
} else {
|
||||||
last;
|
|
||||||
$handled = 1;
|
$handled = 1;
|
||||||
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
say "The url could not be handled, post a issue on https://gitea.sergiotarxz.freemyip.com/sergiotarxz/Peertube-dl/issues telling me the url which does not allow you to download the video so I add support for it." unless $handled;
|
say "The url could not be handled, post a issue on https://gitea.sergiotarxz.freemyip.com/sergiotarxz/Peertube-dl/issues telling me the url which does not allow you to download the video so I add support for it." unless $handled;
|
||||||
|
|
||||||
package Peertube::Downloaders {
|
|
||||||
|
|
||||||
sub gocdn {
|
|
||||||
my $ua = shift;
|
|
||||||
my $response = shift;
|
|
||||||
my ($id) = $response->decoded_content =~ /gocdn\.html#(.+?)"/;
|
|
||||||
|
|
||||||
die "Id undefined" if !defined $id;
|
|
||||||
|
|
||||||
my $gocdn =
|
|
||||||
$ua->get( 'https://streamium.xyz/gocdn.php?v=' . Peertube::Utils::uri_encode($id) )->decoded_content;
|
|
||||||
|
|
||||||
my $google_url = JSON::decode_json($gocdn)->{file};
|
|
||||||
|
|
||||||
my ($filename) = $ARGV[0] =~ s/^.*\///gr . '.mp4';
|
|
||||||
|
|
||||||
$ua->get( $google_url, ':content_file' => $filename );
|
|
||||||
|
|
||||||
say $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub animeid {
|
|
||||||
my $ua = shift;
|
|
||||||
my $response = shift;
|
|
||||||
my @order = ( 'id', 'title', 'refer' );
|
|
||||||
my $url = $ARGV[0];
|
|
||||||
my $url_ajax = 'https://animeid.to/ajax.php?';
|
|
||||||
my ($get_params) = $response->decoded_content =~ /animeid\.to\/streaming\.php\?(.*?)"/;
|
|
||||||
$get_params = {
|
|
||||||
map {
|
|
||||||
my ( $key, $value ) = /^(.*?)=(.*)$/;
|
|
||||||
( $key, Peertube::Utils::uri_decode($value) )
|
|
||||||
} split '&',
|
|
||||||
$get_params
|
|
||||||
};
|
|
||||||
say "Got from $url params for ajax:";
|
|
||||||
print Data::Dumper::Dumper $get_params;
|
|
||||||
say 'Adding passed url as refer.';
|
|
||||||
$get_params->{refer} = $url;
|
|
||||||
my $filename = $get_params->{title};
|
|
||||||
$url_ajax .= join '&',
|
|
||||||
map { join '=', ( $_ => Peertube::Utils::uri_encode( $get_params->{$_} ) ) } @order;
|
|
||||||
say 'Getting video location from: ' . $url_ajax;
|
|
||||||
my $ajax_data = $ua->get(
|
|
||||||
$url_ajax,
|
|
||||||
Referer => $url,
|
|
||||||
Host => 'animeid.to',
|
|
||||||
'X-Requested-With' => 'XMLHttpRequest',
|
|
||||||
)->decoded_content;
|
|
||||||
say "Decoding json... $ajax_data";
|
|
||||||
$ajax_data = JSON::decode_json $ajax_data;
|
|
||||||
die 'No video source found.' if ( !defined $ajax_data->{source} );
|
|
||||||
my $download_url = $ajax_data->{source}[0]{file} // die "No url found.";
|
|
||||||
my $extension = $ajax_data->{source}[0]{type} // die "No extension found.";
|
|
||||||
$filename .= ".$extension";
|
|
||||||
say "Downloading video from $download_url...";
|
|
||||||
my $video_response = $ua->get(
|
|
||||||
$download_url,
|
|
||||||
Referer => $url,
|
|
||||||
Host => 'animeid.to',
|
|
||||||
);
|
|
||||||
if ( $video_response->is_success ) {
|
|
||||||
open my $fh, '>', $filename;
|
|
||||||
$fh->print( $video_response->decoded_content );
|
|
||||||
close $fh;
|
|
||||||
say $filename;
|
|
||||||
} else {
|
|
||||||
die 'Video download failed because: ' . $video_response->status_line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
package Peertube::UserAgent {
|
|
||||||
use parent 'LWP::UserAgent';
|
|
||||||
|
|
||||||
my $last_progress_time;
|
|
||||||
|
|
||||||
sub redirect_ok {
|
|
||||||
1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub progress {
|
|
||||||
my $self = shift;
|
|
||||||
my $status = shift;
|
|
||||||
my $response = shift;
|
|
||||||
if ( !defined $last_progress_time || time > $last_progress_time + 1 ) {
|
|
||||||
$last_progress_time = time;
|
|
||||||
if ( $response->isa('HTTP::Response') && $status =~ /^\d/ ) {
|
|
||||||
say $response->base . ': ' . int( $status * 100 ) . '%';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
package Peertube::Utils {
|
|
||||||
|
|
||||||
sub uri_encode {
|
|
||||||
return map { URI::Encode::uri_encode($_) =~ s/ /+/rg } @_;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub uri_decode {
|
|
||||||
return map { URI::Encode::uri_decode($_) =~ s/\+/ /rg } @_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
92
lib/Peertube/DL/Downloaders.pm
Normal file
92
lib/Peertube/DL/Downloaders.pm
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package Peertube::DL::Downloaders;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use feature 'say';
|
||||||
|
|
||||||
|
use JSON;
|
||||||
|
use Peertube::DL::Utils;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
sub gocdn {
|
||||||
|
my $ua = shift;
|
||||||
|
my $response = shift;
|
||||||
|
my ($id) = $response->decoded_content =~ /gocdn\.html#(.+?)"/;
|
||||||
|
|
||||||
|
die "Id undefined" if !defined $id;
|
||||||
|
|
||||||
|
my $url_gocdn = 'https://streamium.xyz/gocdn.php?v=' . $id;
|
||||||
|
my $response_gocdn = $ua->get($url_gocdn);
|
||||||
|
|
||||||
|
die $response_gocdn->status_line . ' from ' . $url_gocdn unless $response_gocdn->is_success;
|
||||||
|
|
||||||
|
my $google_url = JSON::decode_json( $response_gocdn->decoded_content )->{file};
|
||||||
|
|
||||||
|
my ($filename) = $ARGV[0] =~ s/^.*\///gr . '.mp4';
|
||||||
|
|
||||||
|
say "Descargando desde $google_url.";
|
||||||
|
my $response_google = $ua->get($google_url);
|
||||||
|
|
||||||
|
die $response_google->status_line . ' from ' . $google_url unless $response_google->is_success;
|
||||||
|
|
||||||
|
open my $fh, '>', $filename;
|
||||||
|
|
||||||
|
say "Imprimiendo la respuesta en el fichero.";
|
||||||
|
$fh->print( $response_google->decoded_content );
|
||||||
|
|
||||||
|
close $fh;
|
||||||
|
|
||||||
|
say "$filename descargado.";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub animeid {
|
||||||
|
my $ua = shift;
|
||||||
|
my $response = shift;
|
||||||
|
my @order = ( 'id', 'title', 'refer' );
|
||||||
|
my $url = $ARGV[0];
|
||||||
|
my $url_ajax = 'https://animeid.to/ajax.php?';
|
||||||
|
my ($get_params) = $response->decoded_content =~ /animeid\.to\/streaming\.php\?(.*?)"/;
|
||||||
|
$get_params = {
|
||||||
|
map {
|
||||||
|
my ( $key, $value ) = /^(.*?)=(.*)$/;
|
||||||
|
( $key, Peertube::DL::Utils::uri_decode($value) )
|
||||||
|
} split '&',
|
||||||
|
$get_params
|
||||||
|
};
|
||||||
|
say "Got from $url params for ajax:";
|
||||||
|
print Data::Dumper::Dumper $get_params;
|
||||||
|
say 'Adding passed url as refer.';
|
||||||
|
$get_params->{refer} = $url;
|
||||||
|
my $filename = $get_params->{title};
|
||||||
|
$url_ajax .= join '&',
|
||||||
|
map { join '=', ( $_ => Peertube::DL::Utils::uri_encode( $get_params->{$_} ) ) } @order;
|
||||||
|
say 'Getting video location from: ' . $url_ajax;
|
||||||
|
my $ajax_data = $ua->get(
|
||||||
|
$url_ajax,
|
||||||
|
Referer => $url,
|
||||||
|
Host => 'animeid.to',
|
||||||
|
'X-Requested-With' => 'XMLHttpRequest',
|
||||||
|
)->decoded_content;
|
||||||
|
say "Decoding json... $ajax_data";
|
||||||
|
$ajax_data = JSON::decode_json $ajax_data;
|
||||||
|
die 'No video source found.' if ( !defined $ajax_data->{source} );
|
||||||
|
my $download_url = $ajax_data->{source}[0]{file} // die "No url found.";
|
||||||
|
my $extension = $ajax_data->{source}[0]{type} // die "No extension found.";
|
||||||
|
$filename .= ".$extension";
|
||||||
|
say "Downloading video from $download_url...";
|
||||||
|
my $video_response = $ua->get(
|
||||||
|
$download_url,
|
||||||
|
Referer => $url,
|
||||||
|
Host => 'animeid.to',
|
||||||
|
);
|
||||||
|
if ( $video_response->is_success ) {
|
||||||
|
open my $fh, '>', $filename;
|
||||||
|
$fh->print( $video_response->decoded_content );
|
||||||
|
close $fh;
|
||||||
|
say $filename;
|
||||||
|
} else {
|
||||||
|
die 'Video download failed because: ' . $video_response->status_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1;
|
29
lib/Peertube/DL/UserAgent.pm
Normal file
29
lib/Peertube/DL/UserAgent.pm
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package Peertube::DL::UserAgent;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use feature 'say';
|
||||||
|
|
||||||
|
use LWP::UserAgent;
|
||||||
|
|
||||||
|
use parent 'LWP::UserAgent';
|
||||||
|
|
||||||
|
my $last_progress_time;
|
||||||
|
|
||||||
|
sub redirect_ok {
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub progress {
|
||||||
|
my $self = shift;
|
||||||
|
my $status = shift;
|
||||||
|
my $response = shift;
|
||||||
|
if ( !defined $last_progress_time || time > $last_progress_time + 1 ) {
|
||||||
|
$last_progress_time = time;
|
||||||
|
if ( $response->isa('HTTP::Response') && $status =~ /^\d/ ) {
|
||||||
|
say $response->base . ': ' . int( $status * 100 ) . '%';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1;
|
17
lib/Peertube/DL/Utils.pm
Normal file
17
lib/Peertube/DL/Utils.pm
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package Peertube::DL::Utils;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use feature 'say';
|
||||||
|
|
||||||
|
use URI::Encode;
|
||||||
|
|
||||||
|
sub uri_encode {
|
||||||
|
return map { URI::Encode::uri_encode($_) =~ s/ /+/rg } @_;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub uri_decode {
|
||||||
|
return map { URI::Encode::uri_decode($_) =~ s/\+/ /rg } @_;
|
||||||
|
}
|
||||||
|
1;
|
Loading…
x
Reference in New Issue
Block a user