From 9b2bd19f1a53d17c769e48aa074efe3c836eca5f Mon Sep 17 00:00:00 2001 From: Sophist Date: Mon, 12 May 2014 10:25:02 +0100 Subject: [PATCH] Fix issues in Tags from File Names... 1. Replace all \ with / in path not just last one so it works properly on Windows. 2. Set combo index to show last used string 3. Strip leading zeros from numeric tags like tracknumber. --- picard/ui/tagsfromfilenames.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/picard/ui/tagsfromfilenames.py b/picard/ui/tagsfromfilenames.py index 93a323e71..7d5ee4bb7 100644 --- a/picard/ui/tagsfromfilenames.py +++ b/picard/ui/tagsfromfilenames.py @@ -40,14 +40,19 @@ class TagsFromFileNamesDialog(PicardDialog): self.ui = Ui_TagsFromFileNamesDialog() self.ui.setupUi(self) items = [ + "%artist%/%album%/%title%", "%artist%/%album%/%tracknumber% %title%", "%artist%/%album%/%tracknumber% - %title%", - "%artist%/%album - %tracknumber% - %title%", + "%artist%/%album% - %tracknumber% - %title%", + "%artist% - %album%/%title%", + "%artist% - %album%/%tracknumber% %title%", + "%artist% - %album%/%tracknumber% - %title%", ] format = config.persist["tags_from_filenames_format"] if format and format not in items: items.insert(0, format) self.ui.format.addItems(items) + self.ui.format.setCurrentIndex(items.index(format)) self.ui.buttonbox.addButton(StandardButton(StandardButton.OK), QtGui.QDialogButtonBox.AcceptRole) self.ui.buttonbox.addButton(StandardButton(StandardButton.CANCEL), QtGui.QDialogButtonBox.RejectRole) self.ui.buttonbox.accepted.connect(self.accept) @@ -62,6 +67,7 @@ class TagsFromFileNamesDialog(PicardDialog): item.setText(0, os.path.basename(file.filename)) self.items.append(item) self._tag_re = re.compile("(%\w+%)") + self.numeric_tags = ('tracknumber', 'totaltracks', 'discnumber', 'totaldiscs') def parse_format(self): format = unicode(self.ui.format.currentText()) @@ -71,7 +77,7 @@ class TagsFromFileNamesDialog(PicardDialog): if part.startswith('%') and part.endswith('%'): name = part[1:-1] columns.append(name) - if name in ('tracknumber', 'totaltracks', 'discnumber', 'totaldiscs'): + if name in self.numeric_tags: format_re.append('(?P<' + name + '>\d+)') elif name in ('date'): format_re.append('(?P<' + name + '>\d+(?:-\d+(?:-\d+)?)?)') @@ -79,16 +85,18 @@ class TagsFromFileNamesDialog(PicardDialog): format_re.append('(?P<' + name + '>[^/]*?)') else: format_re.append(re.escape(part)) - format_re.append('\\.(\\w+)$') + format_re.append(r'\.(\w+)$') format_re = re.compile("".join(format_re)) return format_re, columns def match_file(self, file, format): - match = format.search('/'.join(os.path.split(file.filename))) + match = format.search(file.filename.replace('\\','/')) if match: result = {} for name, value in match.groupdict().iteritems(): value = value.strip() + if name in self.numeric_tags: + value = value.lstrip("0") if self.ui.replace_underscores.isChecked(): value = value.replace('_', ' ') result[name] = value