mirror of
https://github.com/fergalmoran/picard.git
synced 2026-05-08 03:56:08 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user