From c06343d871aa0ceb1409e7947d0a130268a9bc56 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@gmail.com>
Date: Thu, 16 Oct 2014 18:19:51 +0200
Subject: [PATCH] new utils::print, already used by sites::parser

---
 lib/utils/print.pm | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 lib/utils/print.pm

diff --git a/lib/utils/print.pm b/lib/utils/print.pm
new file mode 100644
index 0000000..ed0b518
--- /dev/null
+++ b/lib/utils/print.pm
@@ -0,0 +1,48 @@
+package utils::print;
+
+use strict;
+
+# Used to print a content.
+# The public subroutine is print($content).
+# arg :
+#   - $content : a ref to a hash with the following keys :
+#       - id
+#       - title
+#       - author
+#       - duration (in seconds)
+#       - url
+#       - tags : a ref to a list of tags
+# returns :
+#   - a string well formated
+
+sub print {
+    my ($content) = @_;
+
+    my $msg = '['.$content->{'id'}.'] '.$content->{'title'};
+
+	if (defined $content->{'author'}) {
+		$msg .= ' | '.$content->{'author'};
+	}
+
+    if (defined $content->{'duration'}) {
+        my $h = int($content->{'duration'} / 3600);
+        my $m = int(($content->{'duration'} % 3600) / 60);
+        my $s = int(($content->{'duration'} % 3600) % 60);
+
+        $msg .= ' (';
+        $msg .= sprintf("%02d:", $h) if ($h > 0);
+        $msg .= sprintf("%02d:", $m);
+        $msg .= sprintf("%02d", $s);
+        $msg .= ')';
+    }
+
+    $msg .= ' => '.$content->{'url'} if (defined $content->{'url'});
+
+    if (defined $content->{'tags'}) {
+        $msg .= ' '.$_ foreach (@{$content->{'tags'}});
+    }
+
+    return $msg;
+}
+
+1;
-- 
GitLab