From 75aa7a544a79f86a880a0b9e04bfedd65c6f3b85 Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Fri, 29 Nov 2024 07:27:09 +0100 Subject: [PATCH] In /files view, also show file sizes. --- src/templates/files.tmpl | 2 ++ src/ytplom/misc.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index a44066b..2d58c5b 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -11,8 +11,10 @@ show absent: <input type="checkbox" name="show_absent" {% if show_absent %}check <p>known files (shown: {{files|length}}):</p> <form action="files" method="POST"> <table> +<tr><th>size</th><th>actions</th><th>path</th></tr> {% for file in files %} <tr> +<td>{{ file.size | round(3) }}</td> <td><input type="submit" name="play_{{file.rel_path_b64}}" value="play" {% if not file.present %}disabled {% endif %}/></td> <td><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a></td> </tr> diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 2bdb0c3..45d2c40 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -391,6 +391,12 @@ class VideoFile(DbData): """Return self.rel_path suffixed under PATH_DOWNLOADS.""" return PATH_DOWNLOADS.joinpath(self.rel_path) + @property + def size(self) -> float: + if not self.full_path.is_file(): + return -1 + return self.full_path.stat().st_size / (1024 * 1024) + @property def present(self) -> bool: """Return if file exists in filesystem.""" -- 2.30.2