1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Fix track duration display

This commit is contained in:
Carey Metcalfe 2024-09-08 14:38:35 -04:00
parent 03b3b652e5
commit bd53ac05f6
2 changed files with 10 additions and 5 deletions

View File

@ -412,9 +412,11 @@ class Track(PathMixin, _Model):
return mimetypes.guess_type(self.path, False)[0] or "application/octet-stream"
def duration_str(self):
ret = f"{(self.duration % 3600) / 60:02}:{self.duration % 60:02}"
if self.duration >= 3600:
ret = f"{self.duration / 3600:02}:{ret}"
m, s = divmod(self.duration, 60)
h, m = divmod(m, 60)
ret = f"{m:02}:{s:02}"
if h:
ret = f"{h:02}:{ret}"
return ret
def suffix(self):

View File

@ -59,7 +59,7 @@ class DbTestCase(unittest.TestCase):
artist=artist,
disc=1,
number=1,
duration=3,
duration=3599,
has_art=True,
bitrate=320,
path="tests/assets/formats/silence.ogg",
@ -74,7 +74,7 @@ class DbTestCase(unittest.TestCase):
artist=artist,
disc=1,
number=2,
duration=5,
duration=3600,
bitrate=96,
path="tests/assets/23bytes",
last_modification=1234,
@ -223,6 +223,9 @@ class DbTestCase(unittest.TestCase):
def test_track(self):
track1, track2 = self.create_some_tracks()
assert track1.duration_str() == "59:59"
assert track2.duration_str() == "01:00:00"
# Assuming SQLite doesn't enforce foreign key constraints
MockUser = namedtuple("User", ["id"])
user = MockUser(uuid.uuid4())