I'd like to include the Track Number in the filename for my MP3's, but many of them include the optional "/<position in set>" E.g. 1/13
4.2.1 TRCK [#TRCK Track number/Position in set]
Not only is this not what I want, it results in very strange directory trees and filenames in Windows! Is there a way to extract just the Track (e.g. 1)?
Example command:
exiftool.exe -r "-Filename<$Artist.$Album.$Track.$Title.%e"
Note: I can't use underscores so I changed them to periods: Warning: [minor] Tag 'Artist_' not defined
You can create a user-defined tag to do any conversions that you want. See this post (https://exiftool.org/forum/index.php/topic,3788.msg17464.html#msg17464) for a similar example.
It sounds like you want a conversion something like this:
ValueConv => '$val=~/(\d+)/; $1',
which will extract only the first integer number from the string.
- Phil
That was very helpful. Here is my config:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
OnlyTrack => {
Require => 'Track',
# only get first integer
ValueConv => '$val=~/(\d+)/; $1',
# an optional PrintConv may be used to format the value
PrintConv => 'sprintf("%02s", $val)',
},
},
);
1; #end