Repository for neat file name string patterns and tagger script snippets

Dear rdswift,

I hope this message finds you well. I am new to MusicBrainz-Picard but have spent a couple of days trying to understand how the scripting process works. Despite my efforts, I struggled to make significant progress until I stumbled upon your code. After downloading and running it, I immediately realized its immense potential in sorting through the 150,000+ songs I’ve accumulated over the past 30 years.

Now, as you might have anticipated, I have a couple of small modifications I’d like to make to your code, but I’m having difficulty figuring out how to do so.

Firstly, I would like to change the sequence from “tracknumber - Title - Artist” to “Tracknumber - Artist - Title”.

Secondly, I have a more complex request. I still use WinAmp and enjoy selecting my music based on my mood. For instance, I’d like to filter songs using criteria such as “?comment has Belgium AND comment has ‘1981’”. This code would retrieve all songs from Belgian artists released during the year 1981. (Yes, I’m originally from Belgium, but 25 years ago we moved to Melbourne, Australia.) In the past, when using MP3Tag, I would denote the country of origin in the Comment box (e.g., the Comment box contained “United Kingdom”). By “country of origin,” I mean the nationality of the artist or band. Is it possible to implement this functionality in your code?

If you don’t mind, I would like to continue using your code going forward. It is truly fantastic and has proven to be incredibly effective. I have great admiration for skilled individuals like yourself.

Thank you in advance for any assistance you can provide.

Best regards,

Luke

Welcome to the wonderful world of Picard, and thanks for the kind words. I’m happy to help, if I can.

If you haven’t already done so, you might want to have a look at the Writing a File Naming Script tutorial. This is intended as a primer to help people get started understanding how to write a file naming script.

The problem I’m having is that I’m not sure which code you want to change.

I assume this is the actual file name structure that you want for the audio files, not including the path portion. Where I’m having trouble understanding is because my file naming script doesn’t output in the format “tracknumber - Title - Artist”. In the filename, the artist name is only included if the credited name is different from standardized album artist name. It appears that you always want to include the artist name in the filename.

This can be done by replacing the actual file name portion of the script (leaving the path portion unchanged) from:

$if($eq(%_nAlbumType%,Classical),$set(_nFileName,%_nTNum%%_nFeat% %_nTNT%))
$if($eq(%_nAlbumType%,Soundtrack),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat%))
$if($eq(%_nAlbumType%,Other),$set(_nFileName,%_nTNum% %_nTNT%))
$if($eq(%_nAlbumType%,Single),$set(_nFileName,%_nYear% %_nTNT%%_nFeat%))
$if($eq(%_nAlbumType%,Standard),$set(_nFileName,%_nTNum% %_nTNT%%_nFeat%))

to something like:

$set(_nFileName,%_nTNum% - %_nFTA% - %_nTNT%)

If I understand you correctly, this would actually be a tagger script (as opposed to a file naming script). If you have both the “Additional Artists Variables” and “Additional Artists Details” plugins enabled (and the “Process track artists” option enabled in the settings for the “Additional Artists Details” plugin), this could be done with the following tagging script:

$set(_tmp,_artist_$getmulti(%musicbrainz_artistid%,0)_)
$set(Comment,$if2($countryname($lower($if2($get(%_tmp%country),$get(%_tmp%begin_country),$get(%_tmp%end_country),xx))),Unknown))

NOTE: The above code snippets are just off the top of my head and have not been tested. If you decide to try them and run into any problems (or if I’ve misunderstood what you’re trying to do), please let me know.

EDIT: The latest version of my file naming script can be found on my github repository.

1 Like

Hi rdswift,

I hope this message finds you well. My apologies for the delayed response; work responsibilities took precedence. I wanted to express my sincere gratitude for your guidance. Although your initial suggestion didn’t align perfectly with my needs, it served as a valuable starting point. With some adjustments, I was able to achieve the desired outcome.

Here’s the line of code that I modified:

$if($eq(%_nAlbumType%,Standard),$set(_nFileName,%_nTNum%%_nFeat% - %_nTNT%)) $noop(This is where I changed the sequence to Track - Artist - Title)

Now, everything functions as intended. I’ve attached a screenshot for your reference.

I’ll need some additional time to address the second part of my request, so I’ll follow up with you later on.

While I’ve reviewed the Writing a File Naming Script page, I found it somewhat limited in addressing my specific needs.

Once again, thank you immensely for your assistance. Wishing you a wonderful day!

Warm regards,

Luke

1 Like

Hello All

Hope you’re all well.

Looking for some help with a script I have and making it more granular but I’m inexperienced enough to not know how to get there.

Here’s the script and it’s product (ignore the file path as it’s temporary):

%_albumartists%/%date%/%album%/$if(%_multiartist%,%artist%,) - %title%
C:\Users\User\Downloads\J. Cole\2024-04-05\Might Delete Later\J. Cole - 3001.m4a

How do I make it so that if there is 1 featured artist, it will list the file as below:

C:\Users\User\Downloads\J. Cole\2024-04-05\Might Delete Later\J. Cole & Cam’ron - Ready ‘24.m4a

And if there is more than 1 featured artist, it lists them as so:

C:\Users\User\Downloads\J. Cole\2024-04-05\Might Delete Later\J. Cole, Daylyt & Ab‐Soul - Pi.m4a

I would like it so that featured artists, when there’s more than one, (following the main artist) is seperated by commas and the last featured artist is preceeded by an ‘&’.

I hope the above makes sense.

Anything else I can provide to illustrate my point, please let me know :slightly_smiling_face:.

Many thanks
Kambo

If you use the “Additional Artists Variables” plugin, splitting the primary and featured artists will aleady be done for you. You then need to test and do the necessay joins in your script. I would do this by iterating through the additional (secondary) artists multi variable using $foreach() and compare the %_loop_count% variable against the total number of artists to determine what separator to use when adding the artist name from the %_loop_value% variable. I would build this to a vew variable that I would then use in the naming script.

1 Like

Thank you so much for such a quick response.

I will give this a go tonight :slight_smile:

Hello RDSwift

I haven’t been able to get to grips with using the plugin and $foreach().

Any assistance you can provide would be much appreciated. I basically have no coding knowledge :joy:.

Hello again :slight_smile:

After losts of reading I have come out with the following:

  *$set(artist,$rreplace(%artist%,\(.*\)\,\([^\,]\$\),\\1 &\\2))*

 *$set(artist,$rreplace(%artist%, with , & ))*

 *$set(artist,$rreplace(%artist%, feat. , & ))*

 *%albumartist%/$decade(%date%)/%album%/%artist% - %title%*

Is there any way to make it so that the below strings only works if there is more than 2 artists?

  *$set(artist,$rreplace(%artist%, with , & ))*
  *$set(artist,$rreplace(%artist%, feat. , & ))*

Appreciate any help with this. :yum:

$lenmulti(%artists%) should return the number of elements in the %artists% multi value variable. You can then use this in a $gt() test.

1 Like

Here is my script hope it helps someone

It will order the library in this order:

D:\A\ACDC\[1975] ACDC - T.N.T. - [flac]

It will create the
Alphabetic first letter of the artist folder
Artist Folder
[Year] Artist Name - Album - [.ext]
Track# - Track Name

$noop(### Configuración de etiquetas basadas en los datos de MusicBrainz ###)

$noop(Asegurarse de que se establezcan múltiples valores para los campos relevantes)
$setmulti(album,%album%)
$setmulti(albumartist,%albumartist%)
$setmulti(artist,%artist%)
$setmulti(year,$if2(%originalyear%,%date:4%)) $noop(Usar el año original si está disponible)
$setmulti(tracknumber,%tracknumber%)
$setmulti(title,%title%)
$setmulti(genre,%genre%)

$noop(### Eliminación de etiquetas no deseadas ###)
$unset(comment) $noop(Eliminar comentarios de las etiquetas)

$noop(### Renombrar y organizar archivos ###)

$noop(Obtener la primera letra del nombre del artista o `#` si comienza con un número o símbolo)
$set(first_letter,$upper($firstalphachar($if2(%albumartist%,%artist%),#)))

$noop(### Crear la estructura de directorios: Letra -> Álbum Artista -> Álbum ###)

%first_letter%/
$if2(%albumartist%,Unknown Artist)/ $noop(Usar albumartist si está disponible, de lo contrario Unknown Artist)
[%year%] %albumartist% - %album% - [%_extension%]/ $noop(Usar albumartist en el nombre del álbum)
$if($gt(%totaldiscs%,1),Disc %discnumber%/,)
$num(%tracknumber%,2) - %title%

$noop(### Mejora de la estructura de directorios ###)

$noop(Agregar país de lanzamiento si está disponible)
$if2(%releasecountry%,Unknown Country) - %album%

$noop(###########################################)
$noop(# Script Information and Legal Notice    #)
$noop(###########################################)

$noop(### Created by: Juan A. Mendez ###)
$noop(### Contact info: universal.onestoptech@gmail.com ###)
$noop(### Script version: 1.0 ###)
$noop(### Date created: September 01, 2023 ###)

$noop(### About this Script ###)
$noop(This script was created to help organize music files based on metadata extracted)
$noop(from MusicBrainz. It automatically renames, structures, and organizes files)
$noop(based on artist, album, track number, and other metadata like genre and release year.)
$noop(The script can handle multi-disc albums and ensures that all information)
$noop(is properly categorized and structured. The result is a neatly organized)
$noop(folder structure that makes music libraries easier to manage and navigate.)

$noop(### Features of the Script ###)
$noop(1. Extracts metadata from MusicBrainz tags such as album, artist, track title, and genre.)
$noop(2. Renames files based on the artist and album name.)
$noop(3. Organizes multi-disc albums into separate folders based on disc number.)
$noop(4. Removes unwanted tags like comments to keep metadata clean.)
$noop(5. Adds country of release to the album folder name if available.)
$noop(6. Automatically creates subfolders based on the first letter of the album artist.)
$noop(7. Supports multiple values for key tags like albumartist and year.)
$noop(8. Creates an easily navigable directory structure for large music libraries.)

$noop(### Legal Notice ###)
$noop(This script is distributed under an open and permissive license. You are free to use, modify,)
$noop(and distribute this script for personal purposes, including adapting it to your needs.)
$noop(The script is provided "as-is" without any warranty of any kind, either expressed or implied.)
$noop(This includes, but is not limited to, the implied warranties of merchantability, fitness for)
$noop(a particular purpose, or non-infringement. The author is not liable for any damages or losses)
$noop(that may arise from the use or inability to use this script, even if advised of the possibility)
$noop(of such damages.)

$noop(### Restrictions ###)
$noop(1. This script is provided solely for personal use. Commercial redistribution or use without)
$noop(the author’s explicit consent is prohibited.)
$noop(2. Users are allowed to modify the script to suit their needs but must not misrepresent its)
$noop(original creation or ownership.)
$noop(3. The author's name and contact information should be retained in any modified versions.)
$noop(4. Users are responsible for ensuring compliance with all applicable laws, including)
$noop(copyright laws and those related to music tagging, distribution, or storage.)

$noop(### Usage Disclaimer ###)
$noop(This script is not affiliated with MusicBrainz or any other music metadata service.)
$noop(While every effort has been made to ensure the accuracy of the metadata processing,)
$noop(the author makes no guarantees regarding the quality or accuracy of the results.)
$noop(Use of this script is entirely at the user's own risk. Users should back up their data)
$noop(before running the script to prevent potential data loss or corruption.)

$noop(### Contact and Support ###)
$noop(If you encounter issues or have suggestions for improving this script, feel free to reach)
$noop(out to the author at universal.onestoptech@gmail.com. While the author is not obligated to)
$noop(provide ongoing support or updates, feedback is always appreciated.)

$noop(### Future Updates ###)
$noop(The script is currently at version 1.0. Updates may be released in the future to improve)
$noop(functionality, add features, or resolve potential bugs. If you wish to receive notifications)
$noop(about updates or new releases, please contact the author via email.)

$noop(###########################################)
$noop(# End of Script                          #)
$noop(###########################################)
1 Like

Probably a piece of cake for most people here, but this is something simple that I just couldn’t find anywhere. Thanks to @tdiaz for the starting piece of this, and @Victini for helping me put it together.

Separate out scripts for Various Artists/VA and Non-VA

$noop(★ Detect Various Artist ★)
$if($eq(%albumartist%,Various Artists),
  $set(_isVarious,1)
)

$noop(VARIOUS ARTISTS SCRIPT)
$if(%_isVarious%,
$noop(any code here will apply to VA)
)

$noop(STANDARD ALBUM SCRIPT)
$if($ne(%_isVarious%,1),
$noop(any code here will apply to non-VA)
)

1 Like