39 lines
745 B
Perl
39 lines
745 B
Perl
package Peertube::DL::UserAgent;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use feature 'say';
|
|
|
|
use LWP::UserAgent;
|
|
|
|
use parent 'LWP::UserAgent';
|
|
|
|
my $last_progress_time;
|
|
|
|
sub redirect_ok {
|
|
my $self = shift;
|
|
return $self->{peertube_redirect_ok};
|
|
}
|
|
|
|
sub set_redirect_ok {
|
|
my $self = shift;
|
|
return $self->{peertube_redirect_ok} = shift;
|
|
}
|
|
|
|
sub progress {
|
|
my $self = shift;
|
|
my $status = shift;
|
|
my $response = shift;
|
|
|
|
$self->{peertube_redirect_ok} = 0;
|
|
|
|
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 ) . '%';
|
|
}
|
|
}
|
|
}
|
|
1;
|