Fix bugs when there are more than 15 results. Set default limit to 25 per page. If you press 'N' it will

show you the next page which more results.
This commit is contained in:
qorg11 2021-11-02 14:44:55 +01:00
parent b385b10b24
commit 4c0590d7fa
No known key found for this signature in database
GPG key ID: 343FC20A4ACA62B9

View file

@ -23,10 +23,11 @@ do $conf_path;
# Prototypes
sub search_video($);
sub search_video($$);
sub select_video($);
sub get_video_data($);
sub play_video($);
our $counter = 0;
# Process arguments
@ -40,25 +41,38 @@ GetOptions(
if (!$ARGV[0]) {
print "No argument given\n";
my $input = $term->readline("=> ");
my $response = search_video($input);
my $json_obj = $json->decode($response);
my $uuid = &select_video($json_obj);
my @selected_video_data = get_video_data($uuid);
my $response;
my $uuid = -1;
my @selected_video_data;
while($uuid == -1) {
$response = search_video($input, $counter);
my $json_obj = $json->decode($response);
$uuid = &select_video($json_obj);
@selected_video_data = get_video_data($uuid);
}
play_video(\@selected_video_data);
} else {
my $response = search_video(join(" ",@ARGV));
my $json_obj = $json->decode($response);
my $uuid = &select_video($json_obj);
my @selected_video_data = get_video_data($uuid);
play_video(\@selected_video_data);
my $response;
my $uuid = -1;
my @selected_video_data;
while($uuid == -1) {
$response = search_video(join("",@ARGV), $counter);
my $json_obj = $json->decode($response);
$uuid = &select_video($json_obj);
@selected_video_data = get_video_data($uuid);
}
play_video(\@selected_video_data);
}
# Functions
sub search_video($) {
my $search_string = shift;
my $response = $ua->get("$config{instance}/api/v1/search/videos?search=$search_string");
sub search_video($$) {
my ($search_string, $counter) = @_;
my $response = $ua->get("$config{instance}/api/v1/search/videos?search=$search_string&count=25&start=$counter");
if ($response->{_rc} == 200) {
return $response->content;
} else {
@ -72,12 +86,17 @@ sub select_video($) {
my @videos_data;
my $total = $json_obj->{total};
$total = 25 if $total > 25;
for (my $i = 0; $i < $total; $i++) {
$videos_data[$i] = $json_obj->{data}->[$i];
print "$i: " . $videos_data[$i]->{name} . "\n";
}
my $input = $term->readline("=> ");
if ($input eq "n" || $input eq "N") {
$counter += 25;
return -1;
}
return $videos_data[$input]->{uuid};
}
@ -85,7 +104,7 @@ sub get_video_data($) {
my $uuid = shift;
my $response = $ua->get("$config{instance}/api/v1/videos/$uuid");
if($response->{_rc} == 200) {
if ($response->{_rc} == 200) {
my $json_obj = $json->decode($response->content);
return ($json_obj->{files}->[$config{default_resolution}]->{fileUrl},
$json_obj->{name},