mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-25 17:13:57 +00:00
Rename variables redefining builtins - tagsfromfilenames.py
This commit is contained in:
@@ -48,13 +48,13 @@ class TagsFromFileNamesDialog(PicardDialog):
|
||||
"%artist% - %album%/%tracknumber% %title%",
|
||||
"%artist% - %album%/%tracknumber% - %title%",
|
||||
]
|
||||
format = config.persist["tags_from_filenames_format"]
|
||||
if format not in items:
|
||||
tff_format = config.persist["tags_from_filenames_format"]
|
||||
if tff_format not in items:
|
||||
selected_index = 0
|
||||
if format:
|
||||
items.insert(0, format)
|
||||
if tff_format:
|
||||
items.insert(0, tff_format)
|
||||
else:
|
||||
selected_index = items.index(format)
|
||||
selected_index = items.index(tff_format)
|
||||
self.ui.format.addItems(items)
|
||||
self.ui.format.setCurrentIndex(selected_index)
|
||||
self.ui.buttonbox.addButton(StandardButton(StandardButton.OK), QtWidgets.QDialogButtonBox.AcceptRole)
|
||||
@@ -74,10 +74,10 @@ class TagsFromFileNamesDialog(PicardDialog):
|
||||
self.numeric_tags = ('tracknumber', 'totaltracks', 'discnumber', 'totaldiscs')
|
||||
|
||||
def parse_format(self):
|
||||
format = self.ui.format.currentText()
|
||||
tff_format = self.ui.format.currentText()
|
||||
columns = []
|
||||
format_re = ['(?:^|/)']
|
||||
for part in self._tag_re.split(format):
|
||||
for part in self._tag_re.split(tff_format):
|
||||
if part.startswith('%') and part.endswith('%'):
|
||||
name = part[1:-1]
|
||||
columns.append(name)
|
||||
@@ -93,8 +93,8 @@ class TagsFromFileNamesDialog(PicardDialog):
|
||||
format_re = re.compile("".join(format_re))
|
||||
return format_re, columns
|
||||
|
||||
def match_file(self, file, format):
|
||||
match = format.search(file.filename.replace('\\','/'))
|
||||
def match_file(self, file, tff_format):
|
||||
match = tff_format.search(file.filename.replace('\\','/'))
|
||||
if match:
|
||||
result = {}
|
||||
for name, value in match.groupdict().items():
|
||||
@@ -109,19 +109,19 @@ class TagsFromFileNamesDialog(PicardDialog):
|
||||
return {}
|
||||
|
||||
def preview(self):
|
||||
format, columns = self.parse_format()
|
||||
tff_format, columns = self.parse_format()
|
||||
self.ui.files.setHeaderLabels([_("File Name")] + list(map(display_tag_name, columns)))
|
||||
for item, file in zip(self.items, self.files):
|
||||
matches = self.match_file(file, format)
|
||||
matches = self.match_file(file, tff_format)
|
||||
for i, column in enumerate(columns):
|
||||
item.setText(i + 1, matches.get(column, ''))
|
||||
self.ui.files.header().resizeSections(QtWidgets.QHeaderView.ResizeToContents)
|
||||
self.ui.files.header().setStretchLastSection(True)
|
||||
|
||||
def accept(self):
|
||||
format, columns = self.parse_format()
|
||||
tff_format, columns = self.parse_format()
|
||||
for file in self.files:
|
||||
metadata = self.match_file(file, format)
|
||||
metadata = self.match_file(file, tff_format)
|
||||
for name, value in metadata.items():
|
||||
file.metadata[name] = value
|
||||
file.update()
|
||||
|
||||
Reference in New Issue
Block a user