From 74250f810201c37d49b3b4599da2148830fb73c1 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Tue, 4 Jan 2022 17:57:08 +0100 Subject: yt: show video duration --- yt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'yt') diff --git a/yt b/yt index b246b07..4a6280f 100755 --- a/yt +++ b/yt @@ -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) $video->{snippet}{channelTitle} - $video->{snippet}{title} $rating\n"); } close $inh; -- cgit v1.2.3