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};
|
|
|
|
|
2020-12-29 02:29:42 +01:00
|
|
|
my ($filename) = $response->base =~ s/^.*\///gr . '.mp4';
|
2020-12-26 06:18:43 +01:00
|
|
|
|
2020-12-29 02:29:42 +01:00
|
|
|
return { url => $google_url, filename => $filename };
|
2020-12-26 06:18:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub animeid {
|
|
|
|
my $ua = shift;
|
|
|
|
my $response = shift;
|
|
|
|
my @order = ( 'id', 'title', 'refer' );
|
2020-12-29 02:29:42 +01:00
|
|
|
my $url = $response->base;
|
2020-12-26 06:18:43 +01:00
|
|
|
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} );
|
2020-12-29 02:29:42 +01:00
|
|
|
my $download_redirect_url = $ajax_data->{source}[0]{file} // die "No url found.";
|
|
|
|
my $extension = $ajax_data->{source}[0]{type} // die "No extension found.";
|
2020-12-26 06:18:43 +01:00
|
|
|
$filename .= ".$extension";
|
2020-12-29 02:29:42 +01:00
|
|
|
say "Getting redirect to download url from $download_redirect_url...";
|
2020-12-26 06:18:43 +01:00
|
|
|
my $video_response = $ua->get(
|
2020-12-29 02:29:42 +01:00
|
|
|
$download_redirect_url,
|
2020-12-26 06:18:43 +01:00
|
|
|
Referer => $url,
|
|
|
|
Host => 'animeid.to',
|
|
|
|
);
|
2020-12-29 02:29:42 +01:00
|
|
|
if ( $video_response->is_redirect ) {
|
|
|
|
my $video_location = $video_response->header('Location');
|
|
|
|
die "No redirection." unless $video_location;
|
|
|
|
return {
|
|
|
|
url => $video_location,
|
|
|
|
filename => $filename,
|
|
|
|
};
|
2020-12-26 06:18:43 +01:00
|
|
|
} else {
|
2020-12-29 02:29:42 +01:00
|
|
|
die 'Getting redirect failed because: ' . $video_response->status_line;
|
2020-12-26 06:18:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
1;
|