Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Sunday, January 06, 2008

FLAC to WMA Lossless Script

Requires Windows Media Encoders and FLAC.

foreach ( $file in dir *.flac )
{
	# Prep input and output filenames 
	$shortName = $file.Name.Substring(0, $file.Name.Length - $file.Extension.Length);
	$wav = $shortName + ".wav";
	$wma = $shortName + ".wma";
	
	# Decode FLAC to WAV
	& 'C:\Program Files (x86)\FLAC\flac.exe' -d $file.Name

	# Encode WAV to WMA Lossless
	cscript "C:\Program Files\Windows Media Components\Encoder\WMCmd.vbs" -input $wav -output $wma -a_codec WMA9LSL -a_mode 2

	# Cleanup
	del $wav;
}

Wednesday, July 06, 2005

Monad

I was reading a blog from a guy on the Monad team and saw this snippet. Monad (or MSH) is the next command-line from Microsoft. It's a dynamic scripting language. It reminds me of some sort of mix of Bash, PHP, Perl and .NET. I just had my ah-ha moment:

foreach ($f in $feeds) { 

    #snip..

    # read the content from $feeduri as XML 

    $wc = new-object System.Net.WebClient 
    $s = $wc.OpenRead($feeduri) 
    $sr = new-object System.IO.StreamReader($s) 
    $rssdata = [xml]$sr.ReadToEnd() 

    # display title 
    write-host $rssdata.rss.channel.title

    # display title and date of each item 

    $rssx.rss.channel.item | 
        foreach-object { 
            write-host "-" $_.title 
            write-host "     " $_.pubDate 
        } 

}

Look at how Monad allows you to use .NET objects. Also note the implicit xml support; you can navigate the DOM as if it were an object ($rssdata.rss.channel.title). Very cool.