I would like to edit media file tags using TagLib and the MPTag module. But I'm now wondering if my method is even possible. I first exported all the tag properties to a csv file using Get-ChildItem -Path c:\mybooks -Recurse | Get-MediaInfo | export-csv c:\books.csv
So I have all the tag properties and their current value. I've edited the CSV to complete/correct data and now I want to write the corrected values back to the correct media file. I first thought I could set/correct each of the media properties like disc and discount, and artists in the CSV, and then using $_.Disc or $_.DiscCount = to $Media.Disc. The code that looks to me like it has been the closest to working is...
Note: one of the columns in the CSV is "Name", and it contains the full path and file name of the MP3 file. i.e. c:\Books\Book1\File1.mp3
$Files = (Import-Csv "C:\books.csv")
ForEach ($File in $Files) {
$Media = (Get-MediaInfo -Path $File.Name)
$Media.Album = $File.Album,`
$Media.Disc = $File.Disc, `
$Media.DIscCount = $File.DiscCount `
$Media.Save()
}
When I run the script/commands, it takes a minute and looks like it will work, but then I get Exception setting "Composers": "Exception setting "Composers": "Value cannot be null.
Parameter name: value""
At line:14 char:26
+ $Media.Disc = $File.Disc,`
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ScriptSetValueRuntimeException
I'm working with test files and my CSV has a value for every property. If I rem out the Composers line, then Artists is referenced.
If I change $File.<Tag> to $_.<Tag> then my error changes to ...
Property 'Disc' cannot be found on this object; make sure it exists and is settable.
At line:14 char:26
+ $Media.Disc = $_.Disc,`
+ ~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Is my problem the fact I'm working with two different object types (between the media file and the CSV object)? I'm thought my csv values would be passed along as a string, and my variable either $File.<tagproperty> or $_.<tagproperty> would accept the string.
It looks to me like $File.<tagproperty> is taking the value from the csv file, because if I query the variable, I get the value form the csv file. So at this point, I don't know if I keep trying, or if it's a mute point because I cannot read media tag properties from a CSV and match them up to the correct media file???
If anyone can assist me, I would be grateful,
Thank you,
Dean