Zune music backup
Last night I decided to tackle a minor, but annoying, problem in my household. I have a Zune and I use my 10 credits every month to buy music that I like. I don’t have physical media for these songs and perhaps I’m just old school, but I wanted physical copies of my music as a backup. The secondary purpose was to be able to play the CDs in my car. My 3rd purpose was to write the music not as a typical music CD but as data so I could fit more songs per CD. My 4th purpose was to start building my powershell skills, which I’m lagging behind much of the world on developing.
When I purchase my music I have been adding it to a playlist, for tracking. The physical files are in various directories and it was going to be a pain to track them all down to copy to the cd to burn. Instead I decided it was time to brush up on my powershell some and wrote the script below one night.
You will notice there are some TODO items. There are a few “fit and finish” pieces to handle, but the script functions as is. I will be cleaning up my personal copy but I wanted to get this quickly posted for my friends who wanted to see it.
The script accesses a saved ZUNE playlist, finds all the files from that playlist, and copies them all to one single directory which you can then burn to CD.
“This software (or sample code) is not supported under any Microsoft standard support program or service. The software is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the software and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the software be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the software or documentation, even if Microsoft has been advised of the possibility of such damages.”
##------------------------------------------------------------------------------------------------------------
## Created by Michael Griswold on 8-16-11
## Last updated: 8-17-11
##
## This script will parse the XMl from a Zune playlsit file (ZPL) and then copy each listed file to a specific
## directory. You can then burn to CD as native MP3 files for playback on MP3 aware CD systems.
##
## Reminder: Run this to allow execution of this script on yoru PC: set-executionpolicy remotesigned
##
##------------------------------------------------------------------------------------------------------------# TODO: Add in ability to read in values from the command line.
[string]$ZPLFilepath="C:\Users\Mike\Music\Playlists\To Burn.zpl"
[string]$Outputpath="c:\temp\ZPLOutput\"
## Prompt for ZPL file, with full path
"ZPL file path is hard coded"
"Output directory is hardcoded (and must be pre-created) to c:\temp\ZPLOutput"## Parse XML file
[System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
$xd.Load($ZPLFilePath)## Fetch the music files and paths
$nodelist = $xd.selectnodes("/smil/body/seq/media")
Write-Output $nodelist
# $nodelist | Get-Member | more## Parse all the media tags to find the file name
foreach($mediaNode in $nodelist)
{
# "Entering foreach"
# $mediaNode | get-member | more
$path=$medianode.src
Write-output $path
## copy the files to a final location
Copy-Item $path $OutputPath
}# TODO: Add validation on user inputs