News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Renaming an MP3 file using TrackNumber

Started by barmst02, July 05, 2012, 11:25:51 AM

Previous topic - Next topic

barmst02

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


Phil Harvey

You can create a user-defined tag to do any conversions that you want.  See this post 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

barmst02

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