Bulk Convert Follow-Up

Two things have changed.  I decided to undelete the whole WMA library and re-convert to 320kbps instead of 192kbps.

Second; Plex has decided to shut down the service for which I was preparing my music.  I don’t know what I’ll do next but I will make updates as I find out more.

Here’s the new script for the conversion.  It takes care of the square brackets, long file/paths, and some other stuff.

$m = "\\?\C:\Users\jason\OneDrive\Music\"

Get-ChildItem -Path $m -Filter '*[*' -Recurse | % {Rename-Item -LiteralPath $_.fullname -NewName $_.fullname.replace("[","(")}
Get-ChildItem -Path $m -Filter '*]*' -Recurse | % {Rename-Item -LiteralPath $_.fullname -NewName $_.fullname.replace("]",")")}

$batchtoconvert = gci -LiteralPath $m -Filter *.wma -Recurse

$batchtoconvert.Count

foreach ($filename in $batchtoconvert)
{
    write-host $filename.FullName
    $st = get-date
    $input = $filename.FullName
    $output = $filename.FullName -replace ".wma", ".mp3"
    & "C:\Users\jason\OneDrive\Documents\ffmpeg\bin\ffmpeg.exe" -i $input -ab 320k -map_metadata 0 -id3v2_version 3 $output -y -loglevel panic
    $et = get-date
    $ts = [DateTime]$et - [DateTime]$st
    write-host $ts.seconds " seconds"
    Remove-Item $filename.FullName -Force
}

Bulk Convert WMA to MP3

Don’t care about the what or why?  Skip to the how below.

Many years ago, I decided that lossless WMA was going to be the wave of the future.  My Creative Labs Zen played them beautifully when the world still hadn’t accepted FLAC.

It was a weird time for music.  Ipods weren’t a thing yet and the world didn’t know what to do with digital music.  Solid storage was impractically expensive and almost no MP3 players had it.  If they did, 64 megabytes of flash storage was equivalent to a 500 megabytes of magnetic disk storage.

Basically the answer was to go backward from everything we worked toward to have our home audio closely match the real thing and use absolute crap quality, highly compressed audio files so we could carry them to the gym.  Disgusting.

I did my research way back then and I believe my argument for the lossless WMA was both that WMP ripped them quicker than lossless MP3s and, more interestingly, supposedly it was less disk access to read them.  Think about it this way – highly compressed media needs to be decompressed.  This uses processing power and battery.  Less compression (or zero compression) only needs to be read from the disk, quickly interpreted, and then turned into audio.

Back in 2003-ish, I was convinced of this and ripped tons of my personal CDs into WMAs.  Eventually the Zune popped up and though it will be forever mocked, was a solid MP3 player.  It handled WMAs just fine so I still felt comfortable with my decision made a decade prior.

Later on, post Zune, I had a Windows Phone which, again, played WMAs without any issue.  Eventually I moved away from that (forcefully) and am now on an Android.  Androids can play WMA files just fine and Microsoft’s Groove player did a fine job of that.  Still, fifteen years later, I felt like it was a fine decision.  More so now that my files were stored online and bandwidth isn’t even a consideration any longer.

Recently Microsoft announced a plan to sunset (kill) the Groove player on all platforms except Microsoft platforms.  Unfortunately this left me in a rut as the final kill will happen in a few months and I’d still like to listen to these.

Plex has a cloud service that, well, sucks.  It’s supposed to read the files from your OneDrive account and give you a serverless playback option.  It works great with MP3 files but struggles greatly with WMAs regardless of platform.  I looked for many other options and everything seems to struggle.  I don’t know if it’s an on-fly conversion or some caching issue but WMAs are a thing of the past and I’m accepting that my twenty-year-ago decision was the wrong one.

But to be fair, nobody knew what would happen.

Being in OneDrive, it’s easy to sync up my library.  I recently went through the process of converting all of the WMA files into 192kb MP3 files.  File sizes shrank drastically as did quality.  I wasn’t looking to save space, I was looking to stream my music reliably and file size is important.

HOW

If you’re like me and you keep your music up on OneDrive and want to play it anywhere at any time, give this a try.  What I’m using:

  • Windows 10
  • OneDrive (built in)
  • Plex Cloud
  • PowerShell (built in)
  • ffmpeg

First off, you’ll need to download all of the WMAs.  My collection has a combination of many file types collected over eighteen years but we’ll convert these.

Mine are all gone so here’s a dummy.  Select all (ctrl + a) and right click, choose “Always keep on this device”.  This will start the OneDrive mega sync.  All of the WMA files, regardless of folder within your “music” folder, will begin to download.  This was about 60GB for me.

Then you wait.  Go download ffmpeg while you wait and extract it somewhere.  It doesn’t need to be installed.

Find the directory of the “ffmpeg.exe” file.  This is the tool that we’ll use to do the conversions.

Next we’re going to open up PowerShell.  I’ve written the script here.  It’s sloppy but it works and we’re not going for anything permanent.  Here’s the script.

$m = "C:\users\jason\OneDrive\Music\*"
#$m = "\\?\C:\users\jason\OneDrive\Music\*"

$batchtoconvert = gci -Path $m -Filter *.wma -Recurse

foreach ($filename in $batchtoconvert)
{
	write-host $filename.FullName
	$st = get-date
	$input = $filename.FullName
	$output = $filename.FullName -replace ".wma", ".mp3"
	& "C:\PATHTOFFMPEG\bin\ffmpeg.exe" -i $input -ab 192k -map_metadata 0 -id3v2_version 3 $output -y -loglevel panic
	$et = get-date
	$ts = [DateTime]$et - [DateTime]$st
	write-host $ts.seconds " seconds"
	Remove-Item $filename.FullName -Force
}

What’s it do?  We’ll go through it.

To get PowerShell open on a Windows computer, push WindowKey + R, type “powershell ise”, and push enter.  Copy/paste that script into the TOP window.

The first line is the main path of your music folder.  Under this, in any subfolder, you’ll have your WMA files.

The second line is to be used if paths get REALLY LONG.  It might be best to use this instead.  The pound symbol is a comment.

The next chunk says “give me a list of WMA files in all of these directories and sub directories”.

Then we get to the loop.  The next thing you need to change is that c:\PATHOFFFMPEG\.  Make sure to put the path of the ffmpeg.exe file you downloaded from the website earlier.

What this will do is take each one, name by name, and convert it a 192kb MP3 file, preserving the metadata and embedded album art on the way.  Cool!  It will also remove the WMA file (if it can – more on that below) so that the MP3 can effectively take its place.

To run it, highlight the whole text and push F8.

I recommend testing a few at a time.  You explicitly specify a directory to convert or even a whole letter.  I did my collection letter by letter with “…\A*” to get all the A’s.  This was not necessary but I worry about things and my computer is pushing seven years old so I wanted to keep an eye on it.

I actually ran two instances of PowerShell and ran a letter of the alphabet in each one.  T and S took the longest and it let more cores do more work.

A few caveats that could be fixed if you wanted to spend the time fixing them:

Paths that are too long will break it.  If it simply doesn’t work from the start, try a shorter or more explicit directory and see if that works.  You might have some long stuff.  You can also try using the “\\?\” syntax in front of the path to hint at the long paths.  If you have bad habits about giving paths crazy deep or long names, this can be a problem.  Play around with it.

Second, if a file or folder has [square brackets] anywhere, it will break the delete part of the script because I never bothered to escape them.  What I recommend is either write that in yourself (haha) or after you’re all converted, do another search for all the remaining WMA files.  You might notice that they all have a square bracket somewhere.  You can bulk delete them this way.  This won’t prevent them from being converted, just deleted.

Third and what should have been at the very top of this post: do this at your own risk.  You’re deleting your old WMAs, replacing them with MP3s, and eating a ton of bandwidth on the way.

  • OneDrive will go into frantic scan and upload mode during this process if you do it in the live sync’d directory.  Let it.
  • You will break your old playlists because they likely depended on the other filenames.
  • OneDrive will keep everything deleted for at least a month in the online recycle bin.  If everything gets really screwed up, you can bring back your old stuff.
  • KEEP YOUR MEDIA PLAYER CLOSED!  If it’s trying to scan this stuff while you do this, you’re going to make it vomit.
  • Be patient.

If this all works out for you, Plex offers a cloud player that will supposedly grab your files from OneDrive and play them anywhere you can install the app.  It works on Windows, Android handhelds and TVs, and the website.  It’s a great app but their handling of the streaming is sub-par.  I don’t recommend Plex right now but when the next thing comes around, the MP3 files will most likely be where the world wants you to be.  This time, I’ll be ready.

I’m considering a hosted personal server.  If I go that route, I’ll share all Linux commands and the scripting along the way.

Expect a follow up post in 2034 with the “I was wrong again – here’s how to really do it” explanation.

Have fun.

Slimming Down

I’ve decided to remove a few things from this site, most noticeably the OneDrive photos link on the navigation bar which I did a few weeks ago.  I look at the odd crawlers that visit this site and it makes me uncomfortable about what is being done and how frequently.  The current plan is to keep the blog where it is but it will have less media.

I also want to reduce the amount of cookies and feelers that visitors have to deal with as I don’t like them myself.  I don’t care who you are but I don’t want to contribute to the tracking/security issues that you face.  The less cross-site stuff on my site, the less you are being stalked by large companies.  You should care about this.

This is a personal decision as I don’t make any money here nor has traffic ever been high.

I will still share images and albums from OneDrive but nothing permanently.  I’ll use links that allow me to set expiration dates.

As the world moves into more “share, like, subscribe” mentality, not only does it exhaust me, it also worries me.  Security and privacy are things we trade for convenience.  Your information is today’s oil.  It shouldn’t be given away and I don’t want to contribute.

A cookie or two gets set on this page by WordPress but it is easily blocked with almost any ad blocker.  I don’t know how to prevent it from being set but feel free to block anything this site tries to set on your own computer.  I don’t care who you are and I don’t need statistics.

If you have questions, leave a (mostly) anonymous comment.  I have a feeling most people reading won’t care but these things are important to our future.

Project CARS 2 Randomizer – Update

I wrote the randomizer script in PowerShell a while ago because I’m pretty comfortable with it and I assumed most people would prefer to run a script on their own rather than download a file that does something mysterious.  I was wrong.  The best possibly compromise in my mind was a web page but I wasn’t sure how to do it.  I haven’t done any web stuff in a very long time.

I read this article and thought it might be worth trying to turn the script into an API.  Within about an hour I had it working.  In another I had all the images imported.  After a third I had the documentation written.  I’ve been hammering at it and so far after a week the cost is three cents!

The idea is that the racing can become stale – same cars, same tracks, over and over.  Even then, some people will be exceptionally good with some car/track combinations.  I love to practice a car or a single track layout but what about the weather?  What about the evening when the track is cool?

You can see from the sample output here (pc2rando.jasonsandwich.com) that you could get anything.  Formula cars in the rain on a rally track?  Go-karts in the snow?  Most combinations are just a bit interesting but some are way out there.  This makes nights racing with friends more fun.

The API will hopefully give someone with more time and talent than me to do something fancy.  I think that this works fine as an web page on your cell phone.  I typically don’t play video games with my computer in front of me.  Maybe someone can turn this into a phone app.

I’ll keep this as a link on my site for quick reference (for me).  You can see it over on the right panel near the bottom.

This would be miserable.