forked from sergiotarxz/Peertube-dl
Initial commit.
This commit is contained in:
parent
5b2e206a5e
commit
d4c8d4d7f8
15
README.md
15
README.md
@ -1,7 +1,12 @@
|
||||
# Peertube-dl
|
||||
|
||||
A little Perl program which downloads videos from some webpages.
|
||||
|
||||
Wants to be something similar to youtube-dl with support for some sites not acceptables under youtube-dl policies.
|
||||
|
||||
Of course the name means Peertube will be supported someday.
|
||||
A little Perl program which downloads videos from some webpages.
|
||||
|
||||
Wants to be something similar to youtube-dl with support for some sites not acceptables under youtube-dl policies.
|
||||
|
||||
Of course the name means Peertube will be supported someday.
|
||||
|
||||
## Supported webpages:
|
||||
|
||||
animeflv.net
|
||||
animeflv.cc
|
||||
|
136
peertube-dl
Executable file
136
peertube-dl
Executable file
@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use feature 'say';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use LWP::UserAgent;
|
||||
use URI::Encode;
|
||||
use JSON;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
my $ua = Peertube::UserAgent->new( timeout => 10 );
|
||||
$ua->agent('Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0');
|
||||
my $response = $ua->get( $ARGV[0] );
|
||||
my %handlers = (
|
||||
gocdn => { reg => qr/gocdn\.html#/, subr => \&Peertube::Downloaders::gocdn },
|
||||
animeid => { reg => qr/animeid\.to\/streaming\.php\?/, subr => \&Peertube::Downloaders::animeid },
|
||||
);
|
||||
|
||||
for my $x ( keys %handlers ) {
|
||||
if ( $response->decoded_content =~ m/$handlers{$x}{reg}/ ) {
|
||||
eval { $handlers{$x}{subr}->( $ua, $response ); };
|
||||
if ($@) {
|
||||
say $@;
|
||||
} else {
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 } @_;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user