home · contact · privacy
Display duration sans milliseconds in /files view too.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 18 Feb 2025 12:53:06 +0000 (13:53 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 18 Feb 2025 12:53:06 +0000 (13:53 +0100)
src/templates/file_data.tmpl
src/templates/files.tmpl
src/ytplom/misc.py

index a2eea56c70b9d77a6e6a19cd5599b08baeb74548..fa1117e02e3c0cefd9aefc4a14dd788dea494ca4 100644 (file)
@@ -40,7 +40,7 @@ no
 
 <tr>
 <th>duration</th>
-<td>{{file.ffprobed_duration}}</td>
+<td>{{file.duration()}}</td>
 </tr>
 
 <tr>
index 553fe03edea3ae35a905fa3c1d53dc0ca0e01b69..c8365e76cbdba870935a7ce8207bd10234b9e310 100644 (file)
@@ -58,6 +58,7 @@ async function update_files_list() {
         const tr = new_child_to('tr', table);
         tr.classList.add("file_row");
         new_child_to('td', tr, file.size);
+        new_child_to('td', tr, file.duration);
         const td_inject = new_child_to('td', tr);
         const btn_inject = new_child_to('button', td_inject);
         btn_inject.onclick = function() { player_command(`inject_${file.digest}`) };
@@ -89,6 +90,6 @@ known files (shown: <span id="files_count">?</span>):
 <button onclick="inject_all();">inject all</button>
 </p>
 <table id="files_table">
-<tr><th>size</th><th>actions</th><th>tags</th><th>path</th></tr>
+<tr><th>size</th><th>duration</th><th>actions</th><th>tags</th><th>path</th></tr>
 </table>
 {% endblock %}
index 164e155d6072babbdf20605ffa73c98fc1917301..28fcab6be7ce17d3cf4da610840b99666390aefc 100644 (file)
@@ -370,6 +370,7 @@ class VideoFile(DbData):
         """Return dict of values relevant for /files."""
         return {
             'digest': self.digest.b64,
+            'duration': self.duration(short=True),
             'present': self.present,
             'rel_path': str(self.rel_path),
             'size': f'{self.size:.2f}',
@@ -446,14 +447,13 @@ class VideoFile(DbData):
             return -1
         return self.full_path.stat().st_size / (1024 * 1024)
 
-    @property
-    def ffprobed_duration(self) -> str:
+    def duration(self, short: bool = False) -> str:
         """Return human-friendly formatting of .duration_ms."""
         if self.duration_ms < 0:
             return '?'
-        ms_str = f'{self.duration_ms % ONE_MILLION}'.rjust(6, '0')
-        n_seconds = self.duration_ms // ONE_MILLION
-        return f'{_readable_seconds(n_seconds)}.{ms_str}'
+        seconds_str = f'{_readable_seconds(self.duration_ms // ONE_MILLION)}'
+        return (seconds_str if short
+                else f'{seconds_str}.{self.duration_ms // ONE_MILLION}')
 
     @property
     def present(self) -> bool: