Browse Source

Audio repr: human readable time

boyska 3 years ago
parent
commit
efe3488799
1 changed files with 14 additions and 2 deletions
  1. 14 2
      feed

+ 14 - 2
feed

@@ -77,6 +77,16 @@ def delta_humanreadable(tdelta):
     return "{}h".format(hours)
 
 
+def duration_humanreadable(seconds):
+    hours = seconds // 3600
+    minutes = (seconds - hours * 3600) // 60
+    seconds = seconds % 60
+
+    if hours > 0:
+        return "{}h{}m{}s".format(hours, minutes, seconds)
+    return "{}m{}s".format(minutes, seconds)
+
+
 class Audio(object):
     def __init__(self, url, duration=None, date=None):
         self.url = url
@@ -91,7 +101,9 @@ class Audio(object):
 
     def __repr__(self):
         return "<Audio {} ({} {})>".format(
-            self.url, self.duration, delta_humanreadable(self.age)
+            self.url,
+            duration_humanreadable(self.duration),
+            delta_humanreadable(self.age),
         )
 
     @property
@@ -130,7 +142,7 @@ class AudioGroup(list):
     def __repr__(self):
         return '<AudioGroup "{}" ({} {})\n{} >'.format(
             self.description,
-            self.duration,
+            duration_humanreadable(self.duration),
             delta_humanreadable(self.age),
             "\n".join("   " + repr(a) for a in self.audios),
         )