Mar 27 2009

Creating Playlists with Powershell Loveliness

So, yeah I finally fixed my one gripe with the sonos, to automatically create playlists of tunage from my libraries:


$tuneagePath = "\\server\music"
$tempPath = "C:\Mike\"

$dailyPlaylistPath = $tempPath + "LastDay.m3u"
"Creating Daily Playlist at " + $dailyPlaylistPath
Get-ChildItem -path $tuneagePath -include *.mp3 -recurse | ? { $_.LastWriteTime -gt [datetime]::Now.Date.AddDays(-1) } | foreach { $_.Fullname }| out-File $dailyPlaylistPath -encoding ASCII

$weeklyPlaylistPath = $tempPath + "LastWeek.m3u"
"Creating Weekly Playlist at " + $weeklyPlaylistPath
Get-ChildItem -path $tuneagePath -include *.mp3 -recurse | ? { $_.LastWriteTime -gt [datetime]::Now.Date.AddDays(-7) } | foreach { $_.Fullname }| out-File $weeklyPlaylistPath -encoding ASCII

$monthlyPlaylistPath = $tempPath + "LastMonth.m3u"
"Creating Monthly Playlist at " + $monthlyPlaylistPath
Get-ChildItem -path $tuneagePath -include *.mp3 -recurse | ? { $_.LastWriteTime -gt [datetime]::Now.Date.AddMonths(-1) } | foreach { $_.Fullname }| out-File $monthlyPlaylistPath -encoding ASCII

"Moving playlists to " + $tuneagePath
$m3uFiles = $tempPath + "*.m3u"
Move-Item $m3uFiles $tuneagePath -force

I run that baby as a scheduled task each night on my server and wake up with three playlists, one showing all the new tunage from yesterday, one for the last week and one for the previous month. Lovely.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Mar 01 2009

I could only hear it in one ear though

Train Horns

Created by Train Horns

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5