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