Added youtube support at webpage.

This commit is contained in:
sergiotarxz 2021-01-09 04:06:55 +01:00
parent 3abba1edce
commit 702e427ef1
Signed by: sergiotarxz
GPG Key ID: E5903508B6510AC2
1 changed files with 26 additions and 8 deletions

View File

@ -16,10 +16,20 @@ get '/' => sub {
post '/api' => sub {
my $c = shift;
my $url = $c->req->json->{url}
// ( return $c->render( text => 'Malformed request due missing url json parameter.', status => 400 ) );
my $url = $c->req->json->{url} // (
return $c->render(
text => 'Malformed request due missing url json parameter.',
status => 400
)
);
my $render_returned;
eval { $render_returned = $c->render( json => Peertube::DL::URLHandler::getDownloadDataFromURL($url) ); };
eval {
$render_returned = $c->render(
json => Peertube::DL::URLHandler::getDownloadDataFromURL(
$url, { format => 18 }
)
);
};
if ($@) {
return $c->render( text => $@, status => 500 );
}
@ -28,9 +38,15 @@ post '/api' => sub {
post '/proxy_to_get' => sub {
my $c = shift;
my $url = $c->req->json->{url}
// ( return $c->render( text => 'Malformed request due missing url json parameter.', status => 400 ) );
die "Not supported url" unless $url =~ s/^https:\/\///r =~ /^storage\.googleapis\.com/;
my $url = $c->req->json->{url} // (
return $c->render(
text => 'Malformed request due missing url json parameter.',
status => 400
)
);
die "Not supported url"
unless ( $url =~ s/^https?:\/\///r =~ /^storage\.googleapis\.com/
|| $url =~ s/https?:\/\///r =~ s/\/.*$//r =~ /googlevideo\.com$/ );
my $ua = Peertube::DL::URLHandler::generateUA();
return $c->render(
data => $ua->get($url)->decoded_content,
@ -38,8 +54,10 @@ post '/proxy_to_get' => sub {
);
};
push @{ app->renderer->paths }, ( Peertube::DL::getDir() . '/Peertube/DL/templates' );
push @{ app->static->paths }, ( Peertube::DL::getDir() . '/Peertube/DL/public' );
push @{ app->renderer->paths },
( Peertube::DL::getDir() . '/Peertube/DL/templates' );
push @{ app->static->paths },
( Peertube::DL::getDir() . '/Peertube/DL/public' );
my $config = plugin 'Config';