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}`) };
<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 %}
"""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}',
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: