Wednesday, August 7, 2013

Powershell and iTunes : Tame iTunes using Powershell.


Hi,

I hope you are doing fine.

Sometime, when you are using window or GUI based programs , you wish for some little bit extra functionality a little bit extra.

I love programming and to be more specific , like to do coding and i love to do automate stuff as per my requirements.

Yesterday night, i was listening to one of my favourite online radio. I use iTunes to listen the internet radios. The most annoying thing is , every time i have to search for a radio and then I am able to listen to it.

At , that time, i think about create a small and tiny script to automate it. So that whenever i open iTunes , it directly start playing my favourite radio channel.

Before i search for iTunes APIs , I think, lets search for iTunes com object and see if we find it.

Luckily i found iTunes.Application as a com object, and from here the fun starts.

Download Script : http://gallery.technet.microsoft.com/scriptcenter/Manage-Apple-iTunes-using-361c20c1

Let’s the fun begin.
Before running the below code, make sure you have iTunes installed on your system.

I added iTunes.Applications as a com object to the $iTune variable.

# Adding iTunes as Powershell Object a
$iTune = New-Object -ComObject iTunes.Application

when you run the above command, this will start iTunes software.

07-08-2013 18-54-37

Now?

Lets play a single .MP3 file.

#Play a single MP3 file.
$iTune.PlayFile("C:\Users\aman.dhally\Music\Bhaag-Milkha-Bhaag\Bhaag Milkha Bhaag - 01 - Gurbani.mp3")

07-08-2013 18-58-19

and here you go , it playing the file which I specified.

How to play an album?

iTunes can play a playlist, to play a whole album, you need to create a album playlist first. and if in PlayFile()
method you have specified a file with is a part of album, then iTunes will play all files in the music album.

# Play a Playlist
$iTune.PlayFile("C:\Users\aman.dhally\Music\Bhaag-Milkha-Bhaag\Bhaag-Milkha-Bhaag.m3u")

Do you want to mute iTunes, no problem.

$iTune.Mute = $true

or un-mute

07-08-2013 19-04-52

and yes, we can set the volume too,

# You are set the Sound volume from 0 to 100
$iTune.SoundVolume = 50

07-08-2013 19-06-54

In the above snapshot the volume is set to 100%.  now lets set it to 50%.

07-08-2013 19-08-09

and here you go.

07-08-2013 19-08-30

Do you want to subscribe to podcasts, yes not a problem

You can see currently i am not subscribed to any podcasts.

07-08-2013 12-12-51

Lets subscribed to our favourite “Powerscripting” podcasts.

# Scubcribe to the podcasts.
$iTune.SubscribeToPodcast("http://feeds.feedburner.com/PowerScripting")
#update Podcast           
$iTune.UpdatePodcastFeeds()

07-08-2013 19-13-15


and here you go.

07-08-2013 12-13-48

Now Lets. come to my main problem.

I love to listen the internet radio channel “Bollywood N Bhangra” on iTunes radio.

07-08-2013 19-15-04

But the problem is every time, i have to search for it to play it and i want iTunes to play it by default.

To find the the URL of my favourite radio channel, i first played it on iTunes and then run the below command.

$iTune.CurrentStreamURL

07-08-2013 19-20-23

i have a URL now. and from that URL i manage to get the M3u file to play.

07-08-2013 19-22-32

Now lets play.

# Opne a web radio
$iTune.OpenURL("http://listen.radionomy.com/bollywood-n-bhangra-usa.m3u")

Bingo.. it is working..

07-08-2013 19-27-07

Now think , that you can write a small Powershell functions and then all plenty of Internet radios of your choice and you just need to type Play-MyFavRadio that’s all. While working on a Powershell console, you can change radio station in iTunes.

Okey, lets try to enable visuals for a fun.

$iTune.VisualsEnabled = $true

07-08-2013 19-28-04

you guys are too demanding, you want to enable Equalizers too?

Ok ok OK.

You can.

# Enable Equlizer
$iTune.EQEnabled = $true

The best thing is when you try to close iTunes it shows a pretty neat warning.

07-08-2013 19-32-56

I have added few tips and trick about iTunes and Powershell in the below Powershell script. Don’t run the script straight away, choose what you need and comment or remove rest.

Download Script : http://gallery.technet.microsoft.com/scriptcenter/Manage-Apple-iTunes-using-361c20c1

Powershell Rocks! and it’s all about automation buddy, it is all about automation.
I hope that you may like this post.
Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007

No comments:

Post a Comment