Skip to content

Commit

Permalink
Fix track duration display
Browse files Browse the repository at this point in the history
  • Loading branch information
pR0Ps committed Sep 8, 2024
1 parent 03b3b65 commit bd53ac0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions supysonic/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ def mimetype(self):
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):
Expand Down
7 changes: 5 additions & 2 deletions tests/base/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def create_some_tracks(self, artist=None, album=None):
artist=artist,
disc=1,
number=1,
duration=3,
duration=3599,
has_art=True,
bitrate=320,
path="tests/assets/formats/silence.ogg",
Expand All @@ -74,7 +74,7 @@ def create_some_tracks(self, artist=None, album=None):
artist=artist,
disc=1,
number=2,
duration=5,
duration=3600,
bitrate=96,
path="tests/assets/23bytes",
last_modification=1234,
Expand Down Expand Up @@ -223,6 +223,9 @@ def test_album(self):
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())
Expand Down

0 comments on commit bd53ac0

Please sign in to comment.