Peertube-dl/bin/peertube-dl-web

62 lines
1.5 KiB
Plaintext
Raw Normal View History

2020-12-29 06:45:06 +01:00
#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
use strict;
use warnings;
use feature 'say';
use Peertube::DL::URLHandler;
use Peertube::DL;
get '/' => sub {
my $c = shift;
return $c->redirect_to('index.html');
};
post '/api' => sub {
my $c = shift;
2021-01-09 04:06:55 +01:00
my $url = $c->req->json->{url} // (
return $c->render(
text => 'Malformed request due missing url json parameter.',
status => 400
)
);
my $render_returned;
2021-01-09 04:06:55 +01:00
eval {
$render_returned = $c->render(
2021-01-13 04:36:15 +01:00
json => Peertube::DL::URLHandler::getDownloadDataFromURL($url) );
2021-01-09 04:06:55 +01:00
};
if ($@) {
return $c->render( text => $@, status => 500 );
}
return $render_returned;
};
post '/proxy_to_get' => sub {
my $c = shift;
2021-01-09 04:06:55 +01:00
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,
format => 'bin'
);
};
2021-01-09 04:06:55 +01:00
push @{ app->renderer->paths },
( Peertube::DL::getDir() . '/Peertube/DL/templates' );
push @{ app->static->paths },
( Peertube::DL::getDir() . '/Peertube/DL/public' );
2020-12-29 12:00:55 +01:00
my $config = plugin 'Config';
app->start;