File naming script - rename two files (with different extensions) at once

Hi,

I am doing a reorganization of a large library of music. Many of those files also have Ableton files associated with them (e.g. if I have SONGTITLE.mp3, then there is also SONGTITLE.mp3.asd). If I were to just rename the plain file, it would lose the association with the relevant Ableton file (because I would end up with SONGTITLEUPDATED.mp3 and SONGTITLE.mp3.asd). Is there a way to have my filenaming script rename both SONGTILE.mp3 and SONGTITLE.mp3.asd at the same time?

Thanks!

1 Like

You can’t currently configure Picard to move those files automatically. There is one special case for WavPack handled where Picard will also move WavPack correction files (.wvc).

It should be possible to implement a plugin with some clever use of file_post_load_processor and file_post_save_processor to handle .asd files as well.

What exactly do these .asd files contain?

2 Likes

They contain cue points, warp markers, basically any work I’ve done on the track in Ableton.

Thanks for the pointer to the plugins. I was going to make a script but I do so much of my management in Picard that I should get my hands dirty with a plugin at this point.

1 Like

If you are familiar with Python take a look at Plugins — MusicBrainz Picard v2.8 documentation and Appendix A: Plugins API — MusicBrainz Picard v2.8 documentation .

For that use case I think especially load and save file hooks are needed. The load one I’d use to detect and remember the .asd file, because the save hook gets called after the deed is done.

The best is always to inspect existing plugins in GitHub - metabrainz/picard-plugins: Picard plugins: use 1.0 branch for Picard < 2.0 (python 2/Qt4) and 2.0 branch for Picard >= 2.0 (python 3/Qt5) , but these specific hooks are not used much.

Somehow I have this vague dĂ©jĂ -vu that I had a similar discussion a while back for some different extra file format. Can’t recall the details, though.

1 Like

You might also want to have a look at the Writing a Plugin tutorial, to help get you started.

2 Likes

Thanks! I think I figured out a good way to set this up. The file object passed by those APIs you pointed out are picard files (not just a path or python file) - so I should be able to add some code to _move_additional_files which should sort this out. Will hopefully have a plugin before the weekend :slight_smile:

1 Like

Actually, I do wonder whether this functionality should be standard in Picard.

If I have an audio file “She loves me.mp3” and have other files with the exact same filename and different extension (“She loves me.lyr”, “She loves me.jpg”) then if Picard is renaming the file, shouldn’t it rename the associated files automatically?

Of course, we should consider counter-examples. One would be if the album was named “She loves me” - then you might not know whether the jpg file was associated with the track or the album. We would also need to deal with the situation where we have “She loves me.mp3” and “She loves me.flac” in the same directory and we rename one or both of these. (And of course the plugin should deal with these counter examples too.)

I guess starting with a plugin to see how this works in practice is a good way forward.

1 Like

I could see it being done with something like the “Move additional files” option - if the extension is included in a list like that, then the file should be renamed and moved. (I was actually very confused by the wording of move additional files - I thought that should do what I was trying to do.) That way a user with .lyr, .txt, .asd, or other associated files could have them automatically move too - but it wouldn’t be on by default.

Would have to be worded carefully to avoid confusion with the existing “Move additional files” though.

Either way, I plan to write a plugin over the next day or two w/ hardcoded movement of ‘.asd’ files, and if there is interest or someone puts in a PR then I will write up an options page to change that to more than ‘.asd’. It should be pretty simple to integrate into Picard directly if there is interest after that.

2 Likes

I made and ran some small tests with a plugin and it seems to be working :slight_smile:

Going to be trying this out on a few thousand songs tonight.

Plugin: GitHub - ElianaTroper/picard-move: move files with specific extensions in Picard

It’s rough, and could be improved, but it might be useful to others already. @outsidecontext your advice was super useful! Thanks.

3 Likes

This is pretty cool. Your approach of patching the method on load is much better and more reliable than my first thought of using the post save hook :+1:

I really think we should add such functionality in Picard and make it generic and configurable, as there are other cases for this behavior. I added [PICARD-2495] Allow configuring companion files to move and rename together with an audio file - MetaBrainz JIRA for this.

One question as I don’t know about the Ableton files: I got this right with the file extension, the Ableton file is always the full name of the corresponding audio file (including the extension) + additional .asd extension, right? So if I have a file MySong.flac there would be a MySong.flac.asd, not MySong.asd?

2 Likes

So if I have a file MySong.flac there would be a MySong.flac.asd, not MySong.asd?

That’s correct for Ableton - MySong.flac would have MySong.flac.asd as well (created on the first time loading MySong.flac in Ableton).

I really think we should add such functionality in Picard and make it generic and configurable, as there are other cases for this behavior.

I think you outlined the general cases well in the ticket. The only edge case I can think of that might be very troublesome would be something like - a user has MySong.flac + MySong.mp3 + MySong.cdg. How would MySong.cdg get moved in that case? Especially if MySong.flac and MySong.mp3 might be moved to different directories if a user uses Picard to separate those releases.

1 Like

That’s an interesting edge case. But actually I think I would not handle this specifically and see if this actually gets a problem in practice. The file would just be moved with the first music file that gets saved.

I would also add the ability to (optionally) associate the file endings for companion files with specific formats. That covers the case of e.g. the WavPack correction files, which only make sense for .wv files. So if you have MySong.mp3, MySong.wv and MySong.wvc the .wvc file would only be moved together with the .wv.

If it turns out this case of multiple music files sharing one companion file is common enough to warrant handling we could introduce some mode where that file gets duplicated when the music files get moved to different targets. But I think that will have quite a few edge cases to handle.

1 Like