Tag from filename or to filename

Maybe I've missed something, because I use DO not that long for tagging my audiofiles, but (how) can I add a filename to a tag or tag to filename?

Tag to filename would be easily done in a regular rename preset or raw command using FILEINFO... here's what I use in my 'Music Tools" toolbar:

Old name: b.(.*)[/b]
New name: {mp3artist}-{mp3album}-{mp3track|#2}-{mp3title}.\2

For the other direction - honestly - I never really adopted much use of Opus for tagging duties due to the inconsistencies in the early v10 releases and having already had decent macros and what not set up in MP3Tag :frowning:... So I don't think theres a native way to go from filename-to-tag, and is probably therefore exactly what you'd then want to do in a script. You could probably do that in a button script, with some fancy handling to pop up some dialogs if some required tag data is missing or something...

If you want help writing that - shout - so long as someone else doesn't chime in with some native way I'm not familiar with or beats me to it :wink:.

But I know you were also looking to expand your scripting chops - so maybe you tackle this one with some pointers :slight_smile: ?

Yes, I want, but the problem is: No time :frowning:!

Well, I've found some small commandline-tools in net and buttons-section, I usually use "artist - track" or "artist - nr. - track", so I just need to create two buttons.

Thanks for the rename-script.

Well then, do you want some help with a script to do filename to tag? Provide your naming conventions and I'll see what I can do... I just mentioned that since you had posted a little ways back about wanting some examples to experiment with :slight_smile:.

You can find some examples in my toolbar (filename to tag, tag to fileman, rename folder from tag, create playlist, add coverart, delete tag...).

Note that I create these buttons before DO11, so maybe that scripts can be improved.
MP3.dop (13.8 KB)

Haven't looked at the buttons honestly - but what method are you using to set the tag based on filename?

Dopus rename scripting...

Look here : "Abusing" Rename Scripts to do other things with file info

Ok, I imagined you were using the old rename script technique to do stuff... I looked at a few of the buttons and it looks like it may very well be worthwhile to adapt it to something using the new scripting interfaces in v11. My main reason for saying so is mainly to make it easier to be of use for a broader range of people. Reason for saying THAT is:

Your 'Tag' buttons assume a naming convention I imagine you try to standardize on... For broader use by others, the new scripting interface in v11 could (for example) provide ScriptCommand based 'Configuration' options where other people can input whatever file naming convention THEY use in order to parse it into the values they want to assign to tag fields. Thanks for sharing...

@AlbatorIV:

Your solution is easy and working! As you almost have a structure in naming your MP3's (e.g. Artist - Track - Title), you only need to edit the code once.

As some of the buttons didn't work correctly, here a working version:

Format: "Artist - Title"

@nodeselect Rename FILEINFO TO="{mp3artist}%{mp3title}" @script vbscript Option Explicit Dim DOpusRTPath DOpusRTPath = "C:\Program Files\Directory Opus\dopusrt.exe" Dim Shell Set Shell = CreateObject("WScript.Shell") Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName ) Dim re, strCommand, artist, title, path Set re = new RegExp re.Pattern = "^(.*) - (.*)(\.mp3)" artist = re.Replace(strFileName, "$1") title = re.Replace(strFileName, "$2") path = strFilePath & "\" & strFileName strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""artist:" & artist & """ ""title:" & title & """" Shell.Run strCommand,0,false Dopus.OutputString "Command: " & strCommand strNewName = "" End Function

Format: "Artist - Track - Title"

@nodeselect Rename FILEINFO TO="{mp3artist}%{mp3track}%{mp3title}" @script vbscript Option Explicit Dim DOpusRTPath DOpusRTPath = "C:\Program Files\Directory Opus\dopusrt.exe" Dim Shell Set Shell = CreateObject("WScript.Shell") Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName ) Dim re, strCommand, artist, track, title, path Set re = new RegExp re.Pattern = "(.*) - ([0-9]*) - (.*)(\.mp3)" artist = re.Replace(strFileName, "$1") track = re.Replace(strFileName, "$2") title = re.Replace(strFileName, "$3") path = strFilePath & "\" & strFileName strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""artist:" & artist & """ ""track:" & track & """ ""title:" & title & """" Dopus.OutputString "Commande: " & strCommand Shell.Run strCommand,0,false strNewName = "" End Function

Format: "Track - Artist - Title"

@nodeselect Rename FILEINFO TO="{mp3track}%{mp3artist}%{mp3title}" @script vbscript Option Explicit Dim DOpusRTPath DOpusRTPath = "C:\Program Files\Directory Opus\dopusrt.exe" Dim Shell Set Shell = CreateObject("WScript.Shell") Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName ) Dim re, strCommand, artist, track, title, path Set re = new RegExp re.Pattern = "([0-9]*) - (.*) - (.*)(\.mp3)" track = re.Replace(strFileName, "$1") artist = re.Replace(strFileName, "$2") title = re.Replace(strFileName, "$3") path = strFilePath & "\" & strFileName strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""track:" & track & """ ""artist:" & artist & """ ""title:" & title & """" Dopus.OutputString "Commande: " & strCommand Shell.Run strCommand,0,false strNewName = "" End Function

To leave behind the rename-script hacks, you maybe like this short snippet I posted some days ago for mykael.
It grabs the track number from the selected file and puts / into the mp3 metadata.
Adjusting this to work with "artist - track - title.mp3" or something, should be very easy and it should be noticeably faster as well.

[code]@script jscript

function OnClick(data){
var files = data.func.sourcetab.selected_files;
var cmd = data.func.command; cmd.ClearFiles();
var re = new RegExp("(.?) (.)(\.mp3)");
for(var i=0;i<files.count;i++){
DOpus.Output("File: [" + files(i).name+"]");
var matches = String(files(i).name).match(re);
if (!matches){ DOpus.Output(" skipped"); continue; }
var track = matches[1]; //var title = matches[2];
var cmdli = 'SetAttr META="track:'+track+'/'+files.count+'" FILE="'+files(i).realpath+'"';
DOpus.Output(" cmd: " + cmdli);
cmd.RunCommand(cmdli);
}
}[/code]