diff options
author | Guillermo Ramos | 2022-01-04 17:57:08 +0100 |
---|---|---|
committer | Guillermo Ramos | 2022-01-04 17:57:08 +0100 |
commit | 74250f810201c37d49b3b4599da2148830fb73c1 (patch) | |
tree | 3a759c1b1c6689b69b3702fb0afa3f1aa5da5f3a /yt | |
parent | 993a9dbf62c5b08c1094b312188bfc8e40dce984 (diff) | |
download | cli-74250f810201c37d49b3b4599da2148830fb73c1.tar.gz |
yt: show video duration
Diffstat (limited to 'yt')
-rwxr-xr-x | yt | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -57,6 +57,16 @@ sub sanitize_rofi { return shift =~ s/&/&/gr; } +sub parse_duration { + my $duration = shift; + my $hours = ($duration =~ /(\d+)H/) ? $1 : 0; + my $minutes = ($duration =~ /(\d+)M/) ? $1 : 0; + my $seconds = ($duration =~ /(\d+)S/) ? $1 : 0; + return $hours == 0 + ? "${minutes}m ${seconds}s" + : "${hours}h ${minutes}m"; +} + sub select_entry { my ($channels, $video_ids) = @_; @@ -91,6 +101,7 @@ sub select_entry { } elsif ($cmi != $mi) { $published = $cmi - $mi . " minutes ago"; } + my $duration = parse_duration($video->{contentDetails}{duration}); my $stats = $video->{statistics}; my $likes = $stats->{likeCount}; @@ -101,7 +112,7 @@ sub select_entry { $rating = "*" x (6 * $likes / $total); } - print $inh sanitize_rofi("($published) [$video->{snippet}{channelTitle}] $video->{snippet}{title} $rating\n"); + print $inh sanitize_rofi("[$duration] ($published) <b>$video->{snippet}{channelTitle}</b> - $video->{snippet}{title} $rating\n"); } close $inh; |