Skip to content

Commit

Permalink
Minor code cleanup for ReleaseGroup._parse_versions
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Jun 9, 2023
1 parent 8ed7d43 commit 3daf66e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions picard/releasegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (C) 2017 Wieland Hoffmann
# Copyright (C) 2017-2018 Sambhav Kothari
# Copyright (C) 2018 Vishal Choudhary
# Copyright (C) 2019, 2021 Philipp Wolfer
# Copyright (C) 2019, 2021-2022 Philipp Wolfer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -73,6 +73,7 @@ def _parse_versions(self, document):
"label": N_('Label'),
"catnum": N_('Cat No'),
}
# additional keys displayed only for disambiguation
extrakeys = ("packaging", "barcode", "disambiguation")

try:
Expand All @@ -85,6 +86,10 @@ def _parse_versions(self, document):
labels, catnums = label_info_from_node(node['label-info'])

countries = countries_from_node(node)
if countries:
country_label = limited_join(countries, 6, '+', '…')
else:
country_label = node.get('country', '') or '??'

if len(node['media']) > max_tracks:
tracks = "+".join(str(m['track-count']) for m in node['media'][:max_tracks]) + '+…'
Expand All @@ -97,8 +102,7 @@ def _parse_versions(self, document):
release = {
"id": node['id'],
"year": node['date'][:4] if "date" in node else "????",
"country": limited_join(countries, 10, '+', '…') if countries
else node.get('country', '') or "??",
"country": country_label,
"format": media_formats_from_node(node['media']),
"label": ", ".join(' '.join(x.split(' ')[:2]) for x in set(labels)),
"catnum": ", ".join(set(catnums)),
Expand All @@ -114,8 +118,10 @@ def _parse_versions(self, document):
data.append(release)

versions = defaultdict(list)

# Group versions by same display name
for release in data:
name = " / ".join(release[k] for k in namekeys).replace("&", "&&")
name = " / ".join(release[k] for k in namekeys)
if name == release["tracks"]:
name = "%s / %s" % (_('[no release info]'), name)
versions[name].append(release)
Expand All @@ -128,13 +134,15 @@ def _parse_versions(self, document):
if value1 != value2:
a['_disambiguate_name'].append(value1)
b['_disambiguate_name'].append(value2)

# build the final list of versions, using the disambiguation if needed
for name, releases in versions.items():
for release in releases:
dis = " / ".join(filter(None, uniqify(release['_disambiguate_name']))).replace("&", "&&")
dis = " / ".join(filter(None, uniqify(release['_disambiguate_name'])))
disname = name if not dis else name + ' / ' + dis
version = {
'id': release['id'],
'name': disname,
'name': disname.replace("&", "&&"),
'totaltracks': release['totaltracks'],
'countries': release['countries'],
'formats': release['formats'],
Expand Down

0 comments on commit 3daf66e

Please sign in to comment.