DEV Community

uyriq
uyriq

Posted on • Updated on

Powershell to fix incorrect encoding of MP3 ID3 tags

This PowerShell script corrects the encoding of ID3 tags in MP3 files. It is specifically designed for the case of a problem where tags encoded in WINDOWS-1251 have been saved to files as WINDOWS-1252 text, and so programs incorrectly output grainy characters (like this one"îñòðîâ") because they read the text as a Western European encoding. So the task is to save tags in modern UTF-8 encoding. TagLibSharp.dll does all the work of reading tags from the file, so to make the script work you need to place this library in the script execution directory. The main purpose of the script is to fix file encoding, but by calling it with the arguments -AllArtists, -AllAlbum, -AllPicture, -AllComment, you can also batch change related meta-properties of files. This script should not be used with diacritic languages, as it considers all these languages to be incorrect Cyrillic characters.

Prerequisites

Before running this script, make sure you have the following:

  • PowerShell 5.1 or higher.
  • TagLibSharp.dll: This is required to work with MP3 tags. You can obtain `TagLibSharp.dll by either: By downloading it from NuGet. Or by compiling the source code available on GitHub.
  • in case of PowerShell 5.1 you need System.Text.Encoding.CodePages.dll (netstandard 2.0) obtain binary package from NuGet that library is defaulted to Powershell Core

How to use

  1. Get TagLibSharp.dll: and optionaly for Powershell 5.1 Get System.Text.Encoding.CodePages
  2. Locate TagLibSharp.dll/System.Text.Encoding.CodePages.dll in the same directory as the script: The script expects TagLibSharp.dll to be in the same directory from which the script is run.
  3. Prepare MP3 files: Make sure that all MP3 files you want to fix are placed in the same directory. The script will process all .mp3 files in the directory from which it is run.
  4. Run the script:.
    • Open PowerShell and navigate to the directory containing the script and TagLibSharp.dll.
    • Run the script by typing .\convertIDv3tags.ps1 and pressing Enter. The script will process each MP3 file in the catalog, correcting the ID3 tag encoding as described.
    • You can optionally pass args as -AllArtists, -AllAlbum, -AllPicture, -AllComment to set the appropriate meta properties for a group of files

Notes

  • Backup your files:Before running the script, it is recommended that you back up your MP3 files to prevent unintentional data loss.
  • Script Restrictions: The script is specifically restricted to working with MP3 files. Changing the -Filter *.mp3 parameter to work with other file formats may not produce the desired results, although in general TagLibSharp.dll supports even video.

**NotaBene: if u wish experiment more with TagLibSharp dive in with

Top comments (0)