Best way to change extension of music file in library?

I have a bunch of songs like this:

% beet ls -p format:MP3 path::m4a$                                                                                                                                       
/Volumes/Fantom HD/Beets/Subvader/(2011)/01 01 Starboard Roller [MP3 320].m4a

You can see the issue.

I need to change the extension to mp3 of tracks like these. What’s the best way to do this while keeping beets in the loop? beets mv is no help here.

% beet mv "Starboard Roller"                                                                                                                                             
Moving 0 items (1 already in place).

Thank you for the help!

That’s a tricky one; beets is pretty hard-coded to preserve extensions when moving files rather than regenerating them. (That’s not necessarily wise, but it does avoid other potential problems with unexpected changes to extensions.)

Fixing this might require some manner of nuclear option. The easiest might be to remove these files from your library, rename them, and then beet import -A them to get them back in. A more advanced version could involve modifying the underlying database directly, but that seems like more trouble than it’s worth…

You could loop across the filenames to rename and update the database accordingly, for example in bash:

# read all filenames into an array
IFS=$'\n' mapfile -t files < <(beet ls -p format:mp3 "path::m4a$")
# move and update
for bad_file in "${files[@]}"; do good_file=${bad_file%.m4a}.mp3; mv -i "$bad_file" "$good_file" && beet modify -y "path::$bad_file" "path=$good_file"; done

mv will prompt you before each operation, - the database won’t get updated if you choose not to move the file.

If you’re completely sure that you want to process all of them, you can remove the -i flag.