God Loves PowerShell (and you too)

I’ve been wanting to work with PowerShell for a long time.  I’ve brought it up a few times but just played around with it.  I never actually did anything with it … that was until a couple of weeks ago.

Our church, Central Baptist Church, records the Sunday morning sermons and puts them online.  However, the sermons weren’t being uploaded. They were being recorded, but weren’t being uploaded and posted to the website.

So I grabbed all of the mp3s from the church’s AV computer and brought them home.  I then opened them in Audacity to chop of any excess content on the beginning and end of the sermons and re-exported them into the /processed/ subfolder.

As I exported them I set the MP3 tag properties like Album, Title, Year, Artist, etc.  This process definitely took the most time – opening each mp3 and normalizing them, stripping the beginning and/or end if needed and exporting them took the entire afternoon.  And now it was almost time for me to head out for the evening services.

Now I needed to actually open up Windows Live Writer to create the blog posts to save each of these sermons.

So my initial problem was that I just created these 49 files with their new filenames, title of the track (Sermon Name) and artist (Speaker Name) but I didn’t have an easy way to get that information back out when I’d create each individual blog post other than right clicking on each one and looking at the file details to see the MP3 tags.

I figured this would be a good problem for PowerShell to solve so I did a quick search for “get multimedia file details in powershell” and the first link that popped up in Bing was:

http://powershell.com/cs/blogs/tobias/archive/2011/01/07/organizing-videos-and-music.aspx

Using this as the starting point I created the following script:

$shell = New-Object -COMObject Shell.Application
$folder = 'D:UsersChadDocumentscbcsermonsprocessed'
$shellfolder = $shell.Namespace($folder)
$sermons = dir $folder

Which produced the following results:

image

I followed that up by

foreach($sermon in $sermons) {
    $shellfile = $shellfolder.ParseName($sermon)

    $shellfile.Name + ' - ' + $shellfolder.GetDetailsOf($shellfile, 21) + ' by ' +
        $shellfolder.GetDetailsOf($shellfile, 13)
}

And those results were:

image

I then just exported that to a text file I was able to read and then copy and paste the values I wanted.

I’m sure there is probably a pretty easy way to generate the blog posts with PowerShell itself either by interfacing with Windows Live Writer or Orchard CMS but I was in a hurry and didn’t have time to look at that.  I was happy with the time I was able to save by getting the data I needed.  I didn’t mind copying and pasting the data from Notepad to Windows Live Writer as I created the individual blog posts.  It would have been cooler to do it via a script, but I was more concerned about getting it done before walking out the door (in the next 10 minutes).

The point here is that I was able to very quickly get up and going with PowerShell.  If I had tons more of files to go through then I would have spent the time to figure out how to automatically create the blog post but that wasn’t my main concern.  Windows Live Writer made that process pretty easy to do manually.

Now that I did that small task, I constantly have a PowerShell window open now (and normally I have 3 different ones opened).  At work and with my personal projects I use Mercurial for source control and always used the command line but now I use PowerShell along with Posh-Hg.  I’ve been digging GitHub recently and am using PowerShell with Posh-Git to grab code from there.

I’ve noticed a lot of C# Console Apps I’ve made over the years could have been more easily done via PowerShell scripts.  Also being able to easily use .net objects I’ve made via PowerShell is also awesome.

So if you haven’t messed with PowerShell yet, but it is on your “to look at” list, then do yourself a favor and load it up and start using it – even for something small.  When all you have is a hammer, everything looks like nail.  Add PowerShell to your tool belt and you will soon see things you would have done a different way before but can now do more efficiently using PowerShell.

God loves you. But does God love PowerShell?  I don’t know, but I believe He is the Ultimate Engineer and so I think He’d dig it.  What I do know is that folks at my church are grateful to finally have the sermons online.  I’d have to think that would cause God to smile as well.

The entire script (with the core wrapped in a function) is below:

$shell = New-Object -COMObject Shell.Application
$folder = 'D:UsersChadDocumentscbcsermonsprocessed'
$shellfolder = $shell.Namespace($folder)
$sermons = dir $folder

function getSermonDetails {
    foreach($sermon in $sermons) {
        $shellfile = $shellfolder.ParseName($sermon)

        $shellfile.Name + ' - ' + $shellfolder.GetDetailsOf($shellfile, 21) + ' by ' +
            $shellfolder.GetDetailsOf($shellfile, 13)
    }
}

getSermonDetails > Sermon_Details.txt

Happy Scripting!

-Chad

From Radians or Degrees to Pi or Tau to a Binary Hand Dance

So last week I wrote a blog post on my XNAEssentials website demonstrating how to create a selection wheel / pie menu in XNA Game Studio 4.  Before I even announced it on twitter, Michael Neel (@ViNull) sent me this tweet.  Then in his @GameMarx podcast on Friday (which I watched on Saturday) he had guest speaker Andy Dunn (@The_ZMan) who he asked if he coded in Degrees or Radians.  It appears both of them code in radians.

Andy then talked about @ViHartViHart of http://vihart.com/ who has math videos including some videos stating that Pi is wrong.  There is this whole movement that I had no idea about.  There is even Tau day (which has good info). So this morning I spent some time looking at a couple of her videos.  They are awesome.  Perhaps I would have done better in Trigonometry if we had used Tau instead of Pi…

If you are interested here are some links:

http://vihart.com/blog/pi-is-still-wrong/

http://vihart.com/blog/pi-politics/

I must say, I’d like to use Tau instead of Pi.

Towards the end of that second video she talks about folks copywriting works based off of Pi and jokingly creates a Binary dance with her fingers.  Her next blog post expands on that and I thought it was great.

http://vihart.com/blog/binary-hand-dance/

So I just tried to add a little humor to my tutorial post about using degrees or radians when calculating angles and as a result I now know about someone I may be able to learn math from in a fun way.

So do a binary hand dance, or write some code, or learn something new …

For me, I’ve been learning Blender 3D.  I’m not an artist by any stretch but I’m able to at least put place holders that resemble the item I’m trying represent in my upcoming 3D game. I’ve learned more in the last 2 weeks about Blender than I have in the last 12 years in other 3D modeling packages. I’m amazed by how quickly some of these folks create things in their tutorials.  There are too many things to learn and no where near enough time. If you are also interested in some good tutorials on Blender 3D, check them out at http://blendercookie.com/

Oh and in case you were wondering … this is what Tau sounds like:

Windows Phone 7 Developer Sweepstakes end June 30th, 2011

If you are almost done with your Windows Phone 7 App or Game, you may want to put a little extra effort into finishing it up and get it certified so you can beat the deadline.

Microsoft’s fiscal year ends June 30th and so do this promotion:

Use Code: 5DXDN

URL: http://bit.ly/WP7DevOffer

If you have 1 app in the marketplace you can win a Samsung Focus. (Details & Rules on the site)

If you have 2 apps in the marketplace you get a refund on your Marketplace account fee.

Register on this site for that: http://phone.microsoftplatformready.com/Offers.aspx

If you have 5 or more apps you can get Free Advertising for one of your apps!

Enter in the WP7 Sweepstakes (Code: 5DXDN; URL: http://bit.ly/WP7DevOffer

If you publish(ed) 5 new apps between April 1 and June 30 you get FREE advertising for one of those apps or games.

So if you are almost done – push through and get it done!

Happy Coding!

Empire Avenue

So what is Empire Avenue?  Well, I hadn’t heard of it before last week. I saw one of @alfredtwo tweets asking about it and I filed it away to look at later. Well, I looked at it last night and decided to join and get going. It is pretty addicting so far. It also encourages creating content (on Twitter, Facebook, your own blogs, YouTube, flickr, etc).

eav-logo-250

I’m still just getting started and can’t comment on how great or terrible it is, but so far I’m enjoying it. Being able to “play the stock market” based on social media activities is a cool concept for sure.

So check it out if you are so inclined!