mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-21 07:04:02 +00:00
Merge Nikolai's $matchedtracks() script function
This commit is contained in:
@@ -394,6 +394,13 @@ class Album(DataObject, Item):
|
||||
def can_refresh(self):
|
||||
return True
|
||||
|
||||
def get_num_matched_tracks(self):
|
||||
num = 0
|
||||
for track in self.tracks:
|
||||
if track.is_linked():
|
||||
num += 1
|
||||
return num
|
||||
|
||||
def get_num_unmatched_files(self):
|
||||
return len(self.unmatched_files.files)
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ class File(LockableObject, Item):
|
||||
for name in metadata.keys():
|
||||
if isinstance(metadata[name], basestring):
|
||||
metadata[name] = sanitize_filename(metadata[name])
|
||||
filename = ScriptParser().eval(format, metadata)
|
||||
filename = ScriptParser().eval(format, metadata, self)
|
||||
# replace incompatible characters
|
||||
if settings["windows_compatible_filenames"] or sys.platform == "win32":
|
||||
filename = replace_win32_incompat(filename)
|
||||
|
||||
@@ -218,9 +218,10 @@ Grammar:
|
||||
self.load_functions()
|
||||
return self.parse_expression(True)[0]
|
||||
|
||||
def eval(self, script, context={}):
|
||||
def eval(self, script, context={}, file=None):
|
||||
"""Parse and evaluate the script."""
|
||||
self.context = context
|
||||
self.file = file
|
||||
self.load_functions()
|
||||
key = hash(script)
|
||||
if key not in ScriptParser._cache:
|
||||
@@ -446,6 +447,13 @@ def func_performer(parser, pattern="", join=", "):
|
||||
values.append(value)
|
||||
return join.join(values)
|
||||
|
||||
def func_matchedtracks(parser, arg):
|
||||
if parser.file:
|
||||
if parser.file.parent:
|
||||
return str(parser.file.parent.album.get_num_matched_tracks())
|
||||
return "0"
|
||||
|
||||
|
||||
register_script_function(func_if, "if", eval_args=False)
|
||||
register_script_function(func_if2, "if2", eval_args=False)
|
||||
register_script_function(func_noop, "noop", eval_args=False)
|
||||
@@ -481,3 +489,4 @@ register_script_function(func_in, "in")
|
||||
register_script_function(func_copy, "copy")
|
||||
register_script_function(func_len, "len")
|
||||
register_script_function(func_performer, "performer")
|
||||
register_script_function(func_matchedtracks, "matchedtracks")
|
||||
|
||||
Reference in New Issue
Block a user