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

PICARD-3012: Sort files by disc no. when submitting cluster as release #2572

Merged
merged 5 commits into from
Jan 8, 2025
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
15 changes: 4 additions & 11 deletions picard/browser/addrelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2021-2023 Philipp Wolfer
# Copyright (C) 2021-2023, 2025 Philipp Wolfer
# Copyright (C) 2021-2024 Laurent Monin
# Copyright (C) 2022 Bob Swift
# Copyright (C) 2022 jesus2099
Expand All @@ -23,6 +23,7 @@


from html import escape
from operator import attrgetter
from secrets import token_bytes

from PyQt6.QtCore import QCoreApplication
Expand Down Expand Up @@ -112,14 +113,6 @@ def serve_form(token):
raise InvalidTokenError


def extract_discnumber(metadata):
try:
discnumber = metadata.get('discnumber', '1').split('/')[0]
return int(discnumber)
except ValueError:
return 1


def _open_url_with_token(payload):
token = jwt.encode(payload, __key, algorithm=__algorithm)
if isinstance(token, bytes): # For compatibility with PyJWT 1.x
Expand Down Expand Up @@ -214,9 +207,9 @@ def mkey(disc, track, name):
disc_counter = 0
track_counter = 0
last_discnumber = None
for f in files:
for f in sorted(files, key=attrgetter('discnumber', 'tracknumber')):
zas marked this conversation as resolved.
Show resolved Hide resolved
m = f.metadata
discnumber = extract_discnumber(m)
discnumber = f.discnumber
if last_discnumber is not None and discnumber != last_discnumber:
disc_counter += 1
track_counter = 0
Expand Down
15 changes: 8 additions & 7 deletions picard/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2006-2007 Lukáš Lalinský
# Copyright (C) 2010, 2018, 2020-2022, 2024 Philipp Wolfer
# Copyright (C) 2010, 2018, 2020-2022, 2024-2025 Philipp Wolfer
# Copyright (C) 2011-2012 Michael Wiencek
# Copyright (C) 2012 Chad Wilson
# Copyright (C) 2013, 2020-2021, 2023-2024 Laurent Monin
Expand Down Expand Up @@ -108,17 +108,18 @@ def load(self, priority=False, refresh=False):
@property
def tracknumber(self):
"""The track number as an int."""
try:
return int(self.metadata['tracknumber'])
except BaseException:
return 0
return self._track_or_disc_number('tracknumber')

@property
def discnumber(self):
"""The disc number as an int."""
return self._track_or_disc_number('discnumber')

def _track_or_disc_number(self, field):
"""Extract tracknumber or discnumber as int, defaults to 0."""
try:
return int(self.metadata['discnumber'])
except BaseException:
return int(self.metadata.get(field, '0').split('/')[0])
except ValueError:
return 0

@property
Expand Down
36 changes: 0 additions & 36 deletions test/test_browser_addrelease.py

This file was deleted.

10 changes: 9 additions & 1 deletion test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2018-2024 Philipp Wolfer
# Copyright (C) 2018-2025 Philipp Wolfer
# Copyright (C) 2019-2022, 2024 Laurent Monin
# Copyright (C) 2021 Bob Swift
# Copyright (C) 2021 Sophist-UK
Expand Down Expand Up @@ -64,13 +64,21 @@ def test_tracknumber(self):
self.assertEqual(42, self.file.tracknumber)
self.file.metadata['tracknumber'] = 'FOURTYTWO'
self.assertEqual(0, self.file.tracknumber)
self.file.metadata['tracknumber'] = '3/12'
self.assertEqual(3, self.file.tracknumber)
self.file.metadata['tracknumber'] = '3 / 12'
self.assertEqual(3, self.file.tracknumber)

def test_discnumber(self):
self.assertEqual(0, self.file.discnumber)
self.file.metadata['discnumber'] = '42'
self.assertEqual(42, self.file.discnumber)
self.file.metadata['discnumber'] = 'FOURTYTWO'
self.assertEqual(0, self.file.discnumber)
self.file.metadata["discnumber"] = '3/12'
self.assertEqual(3, self.file.discnumber)
self.file.metadata["discnumber"] = '3 / 12'
self.assertEqual(3, self.file.discnumber)

def test_set_acoustid_fingerprint(self):
fingerprint = 'foo'
Expand Down
Loading