Tag: Discogs

  • Dino’s Discogs Tagger – fixing my music tags with PowerShell

    My music collection is mostly FLAC rips, and over the years the tags have become a mess. Some albums have no artwork, and genres often just say “Other”. Years tend to be the date of a remaster rather than when the song came out. On top of that, the file names come in half a dozen different styles. Fixing all that by hand wasn’t going to happen. So I wrote Dino’s Discogs Tagger, a single PowerShell script that looks every album up online and then re-tags and renames the files for me.

    The script is also on GitHub, where you can read the code, download it or keep up with changes: github.com/axelthefatcat/dinos-discogs-tagger.

    What it does

    You point it at a folder – a single album, or a whole drive of album folders – and for every folder containing .flac or .mp3 files it:

    • finds the album on Discogs,
    • writes clean tags: title, artist, album artist, album, track and disc numbers (always two digits – 01, 02…) with totals,
    • puts the Discogs genres in the Genre tag and the Discogs styles in the Comment (plus a STYLE tag),
    • sets a single four-digit year – the year the track was first released, not the year of the CD I happen to own,
    • embeds the front cover and a picture of the artist,
    • adds the label, catalogue number and Discogs release ID for reference,
    • and renames each file to a consistent pattern: 01.01 - Billy Idol - Rebel Yell.flac (disc.track – artist – title).

    How the Discogs tagger works

    1. Working out what the album is

    The script first reads whatever tags are already in the files (artist, album, titles, track numbers). If there aren’t any, it falls back to the folder name (Artist - Album) and the numbers at the start of the file names. That gives it something to search Discogs with.

    2. Only offering releases that actually fit

    Discogs lists every pressing of an album separately, and they often have different track lists. So rather than just showing the search results, the script opens each one. It then only offers releases that have the same number of tracks as the folder, where the track titles match the ones in the files. Matching ignores case, punctuation and bracketed extras like “(Remastered)”. Each option shows how well it fits, e.g. [11 tracks, 11/11 titles match].

    Next, you pick one (Enter takes the first). Alternatively, paste a Discogs release URL if you already know the right one, or type a different search. If nothing matched, press A to see every result. Before it writes anything, the script shows a table of old and new file names, plus the year it found for every track. Finally, it asks you to confirm.

    3. Getting the right year

    This was the fiddly part. A “Greatest Hits” CD from 1988 shouldn’t make every song on it look like it came out in 1988. Instead, for each track the script asks MusicBrainz for the recordings of that song by that artist. It then takes the earliest release date. Along the way, it ignores live, demo and remix versions (unless your track is one). It also prefers recordings of a similar length, so album versions and single edits don’t get mixed up.

    For normal studio albums it cross-checks against the Discogs “master” year (the album’s first release) and uses whichever is earlier. For compilations, however, it relies on MusicBrainz only. The preview shows CHECK on any track where the two sources disagree by more than a year, and NOT FOUND on any it couldn’t find. That way, you can spot the odd ones before applying.

    4. Writing the tags – with no extra software

    I wanted this to run on a locked-down Windows PC with nothing but the built-in PowerShell 5.1. As a result, there are no libraries or tools to install. The script reads and writes the tag formats itself:

    • FLAC – rebuilds the Vorbis comment and PICTURE metadata blocks (picture type 3 = front cover, type 8 = artist) and copies the audio across untouched.
    • MP3 – writes an ID3v2.3 tag (TIT2, TPE1, TRCK, TYER, TCON, COMM, APIC and so on).

    The script writes each file to a temporary copy first and only swaps it in once it’s complete. Therefore, a failure part-way through doesn’t damage the original. Tags it doesn’t manage, such as ReplayGain values, stay as they were.

    It also behaves itself with the online services. For example, it keeps Discogs requests under their 60-a-minute limit and MusicBrainz requests under one a second. In addition, it downloads each artist picture only once.

    Using it

    1. Download the zip above and extract Update-MusicTags.ps1.
    2. Get a free Discogs personal access token: log in at discogs.com/settings/developers and click Generate new token. The script asks for it the first time and saves it in %APPDATA%\DinosDiscogsTagger.
    3. Run it – a folder picker pops up:
    powershell -ExecutionPolicy Bypass -File .\Update-MusicTags.ps1

    I’d recommend a dry run on a copy of one album first – -Preview shows exactly what would change without touching anything:

    .\Update-MusicTags.ps1 -Path "D:\Music\Billy Idol\Idol Songs" -Preview

    Options

    OptionWhat it does
    -PathFolder to process (skips the folder picker)
    -PreviewShow the plan, change nothing
    -AutoNo questions – takes the first fully matching release, skips albums with no match
    -NoRenameUpdate tags but keep the existing file names
    -NoRecurseOnly the selected folder, not its sub-folders
    -SaveFolderArtAlso save cover.jpg in each album folder
    -FileNameFormatChange the naming pattern – default {disc}.{track} - {artist} - {title}; also {album}, {albumartist}, {year}

    Good to know

    • Checking every candidate release takes about a second each, so the first list for an album takes around 30 seconds. Choosing a different release afterwards is instant.
    • The year lookup adds roughly a second per track because of MusicBrainz’s rate limit.
    • Some years will differ from what’s printed on the CD – that’s deliberate. Rebel Yell, for example, comes out as 1983, when the song was first released.
    • As with anything that rewrites files in bulk: keep a backup of your music before running it over the whole collection.