Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix track duration display #265

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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