aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xyt13
1 files changed, 12 insertions, 1 deletions
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) <b>$video->{snippet}{channelTitle}</b> - $video->{snippet}{title} $rating\n");
}
close $inh;