Peertube-dl/lib/Peertube/DL/UserAgent.pm

39 lines
745 B
Perl
Raw Normal View History

2020-12-26 06:18:43 +01:00
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;
2020-12-26 06:18:43 +01:00
}
sub progress {
my $self = shift;
my $status = shift;
my $response = shift;
$self->{peertube_redirect_ok} = 0;
2020-12-26 06:18:43 +01:00
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;