Peertube-dl/lib/Peertube/DL/Downloaders.pm

93 lines
2.9 KiB
Perl
Raw Normal View History

2020-12-26 06:18:43 +01:00
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;