One for the archives. Where are the archives?

Hi >

I devised a Powershell script to add tags. It's been done before, I know, but where is a good place to post it in the spirit of sharing?

It wasn't easy to figure out how to use Powershell scriptlets via Mp3tag. There are few examples. (Or they're hidden away in a quiet corner someplace?) This could be one example.

The script runs from Tools. It depends on ffprobe (@ ffmpeg.org) and Taglib library (@ github). You download/clone the Github repos, requiring a certain level of advanced 'know-how'. Anyway, nothing fancy. I use the script to write the number of samples in MP3s to an extended tag. You can change the lines of course to write other tags which are less available directly through Mp3tag.

What's the best practice for posting examples? Here?

Hi & Welcome.

Simply post what you've created and an short tutorial how it works.
Many Freaks and Nerds here :slight_smile: who can give some feedback.

Curious about how you use powershell scripts via mp3tag.

regards,
Peter

I'll try this upload button to see where it uploads to.

samples.zip (2.6 KB)

re: "Don't forget to sign." Under most ExecutionPolicy settings, you must sign *.ps1 files in order for them to run on Windows. I left my digital signature at the bottom. Please remove it before testing the script. Thanks.

Any questions, comments, you know where to find me. (Hope the link works.)

Yes, how to link Powershell scripts with a commandline. A difficult one.

I'm just reading the script ...
well... to many hardcoded path information, you should define an configuration section.
If you need an working path, you should not hardcode. how about creating an subdirectory in %temp% ?

You mean like Boccherini? That's true.

ffmpeg/ffprobe is in the environment path on my system, but it still won't run from Mp3tag, unless you assign an alias, hence the line set-alias ffprobe "G:\Install Programs\CD & DVD\ffmpeg\ffmpeg-2021-02-16-git-8331eb058d-full_build\bin\ffprobe.exe"

Where anyone saves their Github repositories is a personal choice. The hard part is cloning a repo in the first place, in my view. I could remove the path, and leave a blank in square brackets instead. I think though that if you've gone to the trouble to install a Github repo, changing the path is a small matter. Using this script might take about an hour of preparation for someone who hasn't installed ffprobe.exe or taglib-sharp.dll.

Is it worth it? I believe so, if you have a lot of x-tra tags and so forth. You can insert them on the fly.

I can try to include a step-by-step guide in my next post, and take out some of the external paths ...

Might take 24 hours.

take your time... don't rush

Hi >

Here is (supposed to be) a screen capture of the Tools menu. Shown are two Powershell tools.

tools .

Configuring Add Samples Tag requires the following (Windows):

Name: Add Samples Tag
Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parameter: -ExecutionPolicy Bypass -NoProfile -File "[path\to]\samples.ps1" -Path "%_folderpath%\"

Do not tick "for all selected files", as it’s unhealthy.

MP3s contained in the same folder and subfolders of the folder are simultaneously opened for tagging. That happens automatically when you right-click on a file that opens the context menu and click the Add Samples Tag tool.

Configure Add Samples Tag (1 file only):

Name: Add Samples Tag (1 file only)
Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parameter: -ExecutionPolicy Bypass -NoProfile -File "[path\to]\samples-for-one.ps1" -Path "%_folderpath%\" -filename "%_filename_ext%"

You can optionally tick "for all selected files". If you do so at your own peril, selected MP3s are tagged consecutively; a new window opens each time.

Installation.

Download from ffmpeg.org. Extract to a location of your choice.

Visit GitHub - illearth/powershell-taglib: A PowerShell module for manipulating metadata in media files with TagLibSharp. Clone or download the Zip.

Edit the scripts samples.ps1 and samples-for-one.ps1 in a text editor.

Delete the signature blocks. I left them in place to illustrate what a signature will look like when you generate your own.

Input a valid default working folder. In samples-for-one.ps1, provide a default file. Default parameters serve as placeholders in the event that you wish to test run the scripts without a commandline, for example, so don't worry. Default MP3s won't be tagged while launching from Mp3tag, as long as the commandline includes the parameters that are processed.

You must provide the full path locations of ffprobe.exe and taglib-sharp.dll in your editor.

Once you finish editing, save the scripts.

Signing requires a code-signing certificate.

I utilize a small code for signing.

param([string] $file=$(throw "Please specify a filename."))
$cert = @(Get-ChildItem cert:\CurrentUser\TrustedPublisher -codesigning)[0]
Set-AuthenticodeSignature $file $cert

Run in Powershell:

PS [path\to\code]> .\add-signature.ps1 [path\to]\script.ps1

This adds the signature block authorizing Windows to execute a script.

Successful mp3tagging to all.

Caution.

If you already wrote a tag, a new tag is appended, the existing tag not overwritten. You'll end up with two (or three) tags. Mp3tag may show just one tag, but, trust me, there are two of the same name.

Deleting in Mp3tag removes both thankfully.

Do not attempt to remove redundant tags in a PS script requiring a library.

Metatags often reside inside category frames. Typically taglib-sharp.dll empties the frame, the entire category vanishes. Assuming you want to delete a specific tag, you should use Mp3tag for that purpose. It's designed for such tasks and has many additional beneficial traits as well.

The number of samples can be easily calculated as milliseconds and the value written to a *.xspf playlist (Duration) created with a *.mte script. Try it.

Download tools.

samples.zip (4.9 KB)

Contains samples.ps1 and samples-for-one.ps1. (Thanks.)

What is a *.xspf (spiff, for short) playlist? A playlist in Xml format. My Android gobbles them up.

Take a peek.

mp3tag-s7.zip (1.3 KB)

The *.mte source, in case someone's interested.

xspf_vlc_s7.zip (2.2 KB)

It would be nice if Mp3tag featured URL-encode and Html-entity-encode as script functions, natively, like $char(). And as to milliseconds? Why not?

VLC kind of does not support embedded albumart. It's either or. A folder image or an embedded image. Having both screws VLC (phone and PC versions) up a little. Cached album images, whether from an embedded or a folder source, are a hassle to delete from a phone. Another reason to choose *.xspf playlists. Image links are in the playlist, although, again, playlist links don't necessarily override embedded images. VLC gets really confused.

*.xspf playlists are widely implemented, on a range of platforms and players (so I read). Not just VLC on Android gobbles them up.