mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Fix track duration display
This commit is contained in:
parent
03b3b652e5
commit
bd53ac05f6
@ -412,9 +412,11 @@ class Track(PathMixin, _Model):
|
|||||||
return mimetypes.guess_type(self.path, False)[0] or "application/octet-stream"
|
return mimetypes.guess_type(self.path, False)[0] or "application/octet-stream"
|
||||||
|
|
||||||
def duration_str(self):
|
def duration_str(self):
|
||||||
ret = f"{(self.duration % 3600) / 60:02}:{self.duration % 60:02}"
|
m, s = divmod(self.duration, 60)
|
||||||
if self.duration >= 3600:
|
h, m = divmod(m, 60)
|
||||||
ret = f"{self.duration / 3600:02}:{ret}"
|
ret = f"{m:02}:{s:02}"
|
||||||
|
if h:
|
||||||
|
ret = f"{h:02}:{ret}"
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def suffix(self):
|
def suffix(self):
|
||||||
|
@ -59,7 +59,7 @@ class DbTestCase(unittest.TestCase):
|
|||||||
artist=artist,
|
artist=artist,
|
||||||
disc=1,
|
disc=1,
|
||||||
number=1,
|
number=1,
|
||||||
duration=3,
|
duration=3599,
|
||||||
has_art=True,
|
has_art=True,
|
||||||
bitrate=320,
|
bitrate=320,
|
||||||
path="tests/assets/formats/silence.ogg",
|
path="tests/assets/formats/silence.ogg",
|
||||||
@ -74,7 +74,7 @@ class DbTestCase(unittest.TestCase):
|
|||||||
artist=artist,
|
artist=artist,
|
||||||
disc=1,
|
disc=1,
|
||||||
number=2,
|
number=2,
|
||||||
duration=5,
|
duration=3600,
|
||||||
bitrate=96,
|
bitrate=96,
|
||||||
path="tests/assets/23bytes",
|
path="tests/assets/23bytes",
|
||||||
last_modification=1234,
|
last_modification=1234,
|
||||||
@ -223,6 +223,9 @@ class DbTestCase(unittest.TestCase):
|
|||||||
def test_track(self):
|
def test_track(self):
|
||||||
track1, track2 = self.create_some_tracks()
|
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
|
# Assuming SQLite doesn't enforce foreign key constraints
|
||||||
MockUser = namedtuple("User", ["id"])
|
MockUser = namedtuple("User", ["id"])
|
||||||
user = MockUser(uuid.uuid4())
|
user = MockUser(uuid.uuid4())
|
||||||
|
Loading…
Reference in New Issue
Block a user