From 7d6ece1a5accae863dc76e33560bb82cca6ebccb Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Tue, 18 Feb 2025 13:53:06 +0100 Subject: [PATCH] Display duration sans milliseconds in /files view too. --- src/templates/file_data.tmpl | 2 +- src/templates/files.tmpl | 3 ++- src/ytplom/misc.py | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/templates/file_data.tmpl b/src/templates/file_data.tmpl index a2eea56..fa1117e 100644 --- a/src/templates/file_data.tmpl +++ b/src/templates/file_data.tmpl @@ -40,7 +40,7 @@ no <tr> <th>duration</th> -<td>{{file.ffprobed_duration}}</td> +<td>{{file.duration()}}</td> </tr> <tr> diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index 553fe03..c8365e7 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -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 %} diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 164e155..28fcab6 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -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: -- 2.30.2