Posted by: Preetam | March 19, 2007

iTunes and PowerShell

iTunes is amazing player when you think of it from Powershell’s point of view. Truly handy and controls we get in iTunes makes you crazy. I don’t wish to waste my time on saying how much I hate WMP 11. let’s jump to the code. I’m too lazy not to rate my song so I found a new way to do it. Once I rate the song I can push them to my iPod.

 

Powershell to rate song in iTunes

$itunes=new-object -com itunes.application
$CurrentSongRating=$itunes.CurrentTrack.Rating

If($CurrentSongRating -eq ‘0’) {

$Stars=Read-host “You need to rate this Song (1S,2S,3S,4S,5S)”
switch($Stars) {

“1S” {$itunes.CurrentTrack.Rating=’20’}
“2S” {$itunes.CurrentTrack.Rating=’40’}
“3S” {$itunes.CurrentTrack.Rating=’60’}
“4S” {$itunes.CurrentTrack.Rating=’80’}
“5S” {$itunes.CurrentTrack.Rating=’100′}
}
}

else {
$rating=$CurrentSongRating/20
write-host (“Current Rating is ” + “*” * “$rating”)
}


OUTPUT:

PS E:\PowerShell\itunes> .\itunes.ps1
You need to rate this Song (1S,2S,3S,4S,5S): 4s

If the song is rated you get…

PS E:\PowerShell\itunes> .\itunes.ps1
Current Rating is ****
PS E:\PowerShell\itunes>


Daily morning I keep changing my mood, sometime I like romance, sometime I like Devotional and some time only English, but every thime I have to start iTunes and select my mood. I thought lets PowerShell it.

$itunes=new-object -com itunes.application
$itunes.LibrarySource.Playlists | select name
$ToPlay=Read-Host “Select the playlist which you wish to play”
if($ToPlay) {
$CurrentPlaylists=$itunes.LibrarySource.Playlists | where{$_.name -like “$ToPlay”+’*’}
$CurrentPlaylists.PlayFirstTrack()
}

 

OUTPUT

PS E:\PowerShell\itunes> .\playlist.ps1

Name
—-
Library
2 Stars
3 Stars
4 Stars
90’s Music
Music
Music Videos
My Top Rated
Recently Added
Recently Played
Top 25 Most Played
2007
DEvotional
English
Good Collections
MorningSongs
Nights
Podcasts
Romance
SALAAM E ISHQ
Select the playlist which you wish to play: eng

So in order to achieve it, I populate all Playlist and then lazy selected only first three letters and rest is taken care by powershell. 


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: