# iTunes Helpers for PowerShell, by Noah Coad 2009

function Get-iTunes {if ($itunesobj -eq $null) {$itunesobj = New-Object -com iTunes.Application}; $itunesobj; }
function Get-iTunesTrack {(itunes).CurrentTrack}
function Get-iTunesSong {Get-iTunesSongInfo((ittrack))}
function Get-iTunesSongInfo ($track) {$track.Artist + " - " + $track.Name}
function Get-iTunesSongQuoted {"'{0}'" -f (itsong)}
function Get-iTunesPlayList ([string] $name) { (itunes).LibrarySource.Playlists.ItemByName($name) }

function Show-iTunesNowPlaying
{ 
	if ((itunes).PlayerState -eq 1) {$tmp = "Now playing "}
	else {$tmp = "Now paused "}
	$tmp + (itsongq);
}

function itrate { Param ([int]$x); set-itsong; (itunes).CurrentTrack.Rating = $x * 20; Write-Host "Rated" (itsong) $x "stars"; }
function itrate([float]$x) {(ittrack).Rating = $x * 20; Write-Host "Rated" (itsongq) $x "stars"; }
function itnext { (itunes).NextTrack(); Show-iTunesNowPlaying; }
function itplay { (itunes).PlayPause(); Show-iTunesNowPlaying; }

set-alias itpp itplay
set-alias itunes Get-iTunes
set-alias ittrack Get-iTunesTrack
set-alias itsong Get-iTunesSong
set-alias itsongq Get-iTunesSongQuoted
set-alias itPlaylist Get-iTunesPlayList
