Fixing Missing Artists and Albums in Music Library on Server

2 min read

I fixed an issue with missing artists and albums that were not showing up in my music library & learn how I resolved this frustrating problem.


Last weekend I was poking around my music collection on my server and noticed a bunch of artists and albums not showing up in my library (I use Zune to listen to my music and copy it to my phone). Diving in I noticed one folder was full of M4A files… arg! Damn iTunes format… I don’t want Apple or Microsoft format, I want standard plain old MP3! Using the following PowerShell command, I found there were a ton of these types of files on my server:

1Get-ChildItem "\\\RIVERCITY-NAS1\\Music" -recurse -include *.m4a

Yikes… over 800 files! OK, that’s enough to look for a way to automate this conversion process. After a bit of research, I found the freely available VLC player had the ability to convert these types of files… for free. Sweet! So after a little work, I got this PowerShell script working:

 1function ConvertToMp3(
 2    \[switch\] $inputObject,
 3    \[string\] $vlc = 'C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe')
 4{
 5  PROCESS {
 6    $codec = 'mp3';
 7    $oldFile = $_;
 8    $newFile = $oldFile.FullName.Replace($oldFile.Extension,
 9".$codec").Replace("'","");
10    &"$vlc" -I dummy "$oldFile" ":sout=#transcode{acodec=$codec,vcodec=dummy}:standard{access=file,mux=raw,dst=`'$newFile`'}" vlc://quit | out-null;
11    # delete the original file
12    Remove-Item $oldFile;
13  }
14}
15function ConvertAllToMp3(\[string\] $sourcePath) {
16  Get-ChildItem "$sourcePath\\*" -recurse -include *.m4a | ConvertToMp3;
17}
18ConvertAllToMp3 '\\\RIVERCITY-NAS1\\Music';

Sweet… until I noticed all the MP3 files didn’t have any ID3 tags. So I needed to add a step. I found an old copy of the TagLib# library. that would read the tags from one file and copy them to another. So I added the following function to the script:

 1function DuplicateId3Tags
 2{
 3    param (
 4    [string]$sourceM4aTrack,
 5    [string]$targetMp3Track
 6  )
 7
 8  # load sharp library for working with tags
 9    [Reflection.Assembly]::LoadFrom("C:\\Users\\andrew.RIVERCITY\\Documents\\Music Workshop\\taglib-sharp.dll")
10  #load files
11  $sourceM4a = [TagLib.File]::Create($sourceM4aTrack);
12  $targetMp3 = [TagLib.File]::Create($targetMp3Track);
13
14  # copy tags
15  [TagLib.Tag]::Duplicate($sourceM4a.Tag, $targetMp3.Tag, $true);
16
17  $targetMp3.Save();
18}

And added a call to the function right before I delete the original file and voila… 100% MP3 again!

1# update ID3 tags on target file
2DuplicateId3Tags "$oldFile" "$newFile";

Share this article

Feedback & comments