From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 29 Nov 2024 06:27:09 +0000 (+0100)
Subject: In /files view, also show file sizes.
X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/template?a=commitdiff_plain;h=75aa7a544a79f86a880a0b9e04bfedd65c6f3b85;p=ytplom

In /files view, also show file sizes.
---

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."""