from queue import Queue
from sqlite3 import Cursor
# non-included libs
+from ffmpeg import probe as ffprobe # type: ignore
import googleapiclient.discovery # type: ignore
from mpv import MPV # type: ignore
from yt_dlp import YoutubeDL # type: ignore
dir_path.mkdir(parents=True, exist_ok=True)
+def _readable_seconds(seconds: int) -> str:
+ """Represent seconds in (up-to-hours) hexagesimal division."""
+ seconds_str = str(seconds % 60)
+ minutes_str = str(seconds // 60)
+ hours_str = str(seconds // (60 * 60))
+ return ':'.join([f'0{s}' if len(s) == 1 else s
+ for s in (hours_str, minutes_str, seconds_str)])
+
+
class TagSet:
"""Collection of tags as used in VideoFile.tags."""
if dur_char in time_dur:
dur_str, time_dur = time_dur.split(dur_char)
seconds += int(dur_str) * len_seconds
- seconds_str = str(seconds % 60)
- minutes_str = str(seconds // 60)
- hours_str = str(seconds // (60 * 60))
- self.duration = ':'.join([f'0{s}' if len(s) == 1 else s for s
- in (hours_str, minutes_str, seconds_str)])
+ self.duration = _readable_seconds(seconds)
@classmethod
def get_all_for_query(cls,
return -1
return self.full_path.stat().st_size / (1024 * 1024)
+ @property
+ def ffprobed_duration(self) -> str:
+ """Return human-friendly formatting of file duration as per ffprobe."""
+ json = ffprobe(self.full_path)
+ duration_str = json['format']['duration']
+ m_seconds_str = duration_str.split('.')[1]
+ duration_float = float(duration_str)
+ seconds = int(duration_float)
+ return f'{_readable_seconds(seconds)}.{m_seconds_str}'
+
@property
def present(self) -> bool:
"""Return if file exists in filesystem."""