Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - iTunes script

Reply
 
Old 10-21-2009   #1 (permalink)
tonysathre


 
 

iTunes script

I've been looking for a way to embed the iTunes downloaded album art
into the actual MP3 files so when I'm streaming my music from home
computer to my iPhone using Simplify Media, it shows the artwork. I
have found a script that can automate this, but apparently it only
works on iTunes 7. The COM interface, or ActiveX controls must be
different. Could anyone port this script to work with iTunes 9? The
script is below.

'
###############################################################################
' #
' # itunes_insert_artwork.vbs
' #
' # This script will tag your files using artwork downloaded using
iTunes 7
' #
' # written by: Robert Jacobson (http://mysite.verizon.net/teridon/
itunesscripts)
' # Last Updated: 03 Jan 2007
' # Version 1.0
' #
' # This script is GPL v2. see http://www.gnu.org/copyleft/gpl.html
' #
' # Use option "-k" to keep the artwork files extracted
' # (in the same location as the song file)
' # (the default is to remove the files)
'
###############################################################################

Option Explicit

Dim iTunesApp ' iTunes.Application object used to access the
iTunes application.
Dim tracks ' The tracks collection object of the Library
object.
Dim TrackPath ' The path to the track
Dim ArtPath ' The path to the artwork
Dim i ' A counter variable.
Dim Msg ' A string for a message.
Dim f ' A file object.
Dim sources
Dim source
Dim playlists
Dim playlist
Dim playlistName
Dim j
Dim m
Dim c
Dim songName
Dim artist
Dim result
Dim listarray
Dim num
Dim k
Dim track
Dim numtracks
Dim FormatArray(4)
Dim ExtArray(4)
Dim Artobj
Dim Art
Dim ArtDir
Dim Format
Dim BasePath
Dim fso
Dim NumFiles
Dim KeepFiles
Dim args
Dim arg

Set fso = CreateObject("Scripting.FileSystemObject")

FormatArray(0) = "Unknown"
FormatArray(1) = "JPEG"
FormatArray(2) = "PNG"
FormatArray(3) = "BMP"
ExtArray(0) = "unk"
ExtArray(1) = "jpg"
ExtArray(2) = "png"
ExtArray(3) = "bmp"

Set iTunesApp = CreateObject("iTunes.Application.1")
Set sources = iTunesApp.Sources

Dim vers
vers = iTunesApp.Version

Dim Reg1
Set Reg1 = new RegExp
Reg1.Pattern = "^7"
if Reg1.Test(vers) Then
' yay
Else
Wscript.Echo "This script requires iTunes 7"
Wscript.Quit
End If
KeepFiles = False

Set args = WScript.Arguments
' Scan command line arguments
For Each arg in args
' Is it a flag.
If Instr(1, arg, "-", 1) = 1 or Instr(1, arg, "/", 1) = 1 Then
' Check for list flag
If UCase(arg) = "-K" or UCase(arg) = "/K" then
KeepFiles = True
End If
End If
Next

For i = 1 to sources.Count
Set source = sources.Item(i)

IF source.Kind = 1 Then
Set playlists = source.Playlists
Wscript.Echo "Select from the following playlists" & chr(13) & chr
(10)
For j = 1 to playlists.Count
Set playlist = playlists.Item(j)
playlistName = playlist.Name
Wscript.Echo j & ": " & playlistName
Next
Wscript.Echo ""
Wscript.StdOut.Write "Enter comma-separated lists to process: "
result = Wscript.StdIn.ReadLine

listarray = split(result, ",")
For k = 0 to UBound(listarray)
num = listarray(k)
Set playlist = playlists.Item(num)
playlistName = playlist.Name
Wscript.Echo ""
Wscript.Echo chr(9) & "Processing playlist " & num & ": " &
playlistName

Set tracks = playlist.Tracks
numtracks = tracks.Count
Wscript.Echo chr(9) & "tracks: " & numtracks
NumFiles = 0
For m = 1 to numtracks
If m > tracks.Count Then Exit For
Set track = tracks.Item(m)
'Wscript.Echo "num: " & numtracks & " Count: " & tracks.Count
& " m: " & m

If track.Kind = 1 Then
songName = track.Name
artist = track.Artist
TrackPath = track.Location
Set Artobj = track.Artwork
For c = 1 to Artobj.Count
Set Art = Artobj.Item(c)
if Art.IsDownloadedArtwork Then
Format = Art.Format
'Wscript.Echo "Format is " & FormatArray(Format)
ArtDir = fso.GetParentFolderName(TrackPath)
'Wscript.Echo "Artdir is " & ArtDir
'ArtDir = fso.GetBaseName(ArtDir)
Dim RegX
Set RegX = new RegExp
RegX.Pattern = "[/:\\\*\?""""<>]"
RegX.Global = True
songName = RegX.Replace(songName, "-")
'songName = Replace(songName, "/", "-")
ArtPath = fso.BuildPath(ArtDir, songName & "." & ExtArray
(Format))
Wscript.Echo "artpath is " & ArtPath
' save to file
Art.SaveArtworkToFile(ArtPath)
' insert from file into track tag
Art.SetArtworkFromFile(ArtPath)
if (KeepFiles) Then
' nothing
Else
fso.DeleteFile(ArtPath)
End If
NumFiles = NumFiles + 1
End If
Next

End If
Next
Wscript.Echo NumFiles & " files processed in playlist " &
playlistName
Next

'End If
End If
Next


Thanks a lot,

Tony

My System SpecsSystem Spec
Old 10-24-2009   #2 (permalink)
Alexander Mueller


 
 

Re: iTunes script

tonysathre schrieb:
Quote:

> I've been looking for a way to embed the iTunes downloaded album art
> into the actual MP3 files so when I'm streaming my music from home
> computer to my iPhone using Simplify Media, it shows the artwork. I
> have found a script that can automate this, but apparently it only
> works on iTunes 7. The COM interface, or ActiveX controls must be
> different. Could anyone port this script to work with iTunes 9? The
> script is below.
The COM-interface probably didn't change, simply because
that's forbidden to COM-interfaces. That doesn't mean that
some SW-designers don't care about, but it happens fairly rarely.
Sometimes implementation changes, sometimes it gets corrupted
with a new release - but most likely the problem is a different
one, that has to do with data processed or the logic of the script
itself or the communication between the devices or ...

In order for helping you fixing it you should provide details
of the lines of code that don't "work" any more or the
conditions that are no longer met or simply the observations
you make.
Posting 200 lines of code and hope someone will tell you its
line 179, Column 24 will work if the problem is simply
syntactical, but not if it is functional.

So plz, provide some details of what exactly doesn't work

MfG,
Alex


My System SpecsSystem Spec
Old 10-24-2009   #3 (permalink)
Tom Lavedas


 
 

Re: iTunes script

On Oct 24, 8:20*am, Alexander Mueller <mille...@newsgroup> wrote:
Quote:

> tonysathre schrieb:
>
Quote:

> > I've been looking for a way to embed the iTunes downloaded album art
> > into the actual MP3 files so when I'm streaming my music from home
> > computer to my iPhone using Simplify Media, it shows the artwork. I
> > have found a script that can automate this, but apparently it only
> > works on iTunes 7. The COM interface, or ActiveX controls must be
> > different. Could anyone port this script to work with iTunes 9? The
> > script is below.
>
> The COM-interface probably didn't change, simply because
> that's forbidden to COM-interfaces. That doesn't mean that
> some SW-designers don't care about, but it happens fairly rarely.
> Sometimes implementation changes, sometimes it gets corrupted
> with a new release - but most likely the problem is a different
> one, that has to do with data processed or the logic of the script
> itself or the communication between the devices or ...
>
> In order for helping you fixing it you should provide details
> of the lines of code that don't "work" any more or the
> conditions that are no longer met or simply the observations
> you make.
> Posting 200 lines of code and hope someone will tell you its
> line 179, Column 24 will work if the problem is simply
> syntactical, but not if it is functional.
>
> So plz, provide some details of what exactly doesn't work
>
> MfG,
> Alex
You make very good points. I would add that in many cases, it is
backward compatibility that is the problem and that later version are
likely to work, though not guaranteed. I was wondering in this case
if the problem is that the script hard codes a test for version 7 and
not 'greater than 6'. However, since I don't use iTunes (horrors), I
have no way to check if changing the test to allow execution for later
versions would help.
_____________________
Tom Lavedas
My System SpecsSystem Spec
Old 10-25-2009   #4 (permalink)
Steve


 
 

Re: iTunes script

tonysathre wrote:
Quote:

> I've been looking for a way to embed the iTunes downloaded album art
> into the actual MP3 files so when I'm streaming my music from home
> computer to my iPhone using Simplify Media, it shows the artwork. I
> have found a script that can automate this, but apparently it only
> works on iTunes 7. The COM interface, or ActiveX controls must be
> different. Could anyone port this script to work with iTunes 9? The
> script is below.
The script *should* work with iTunes 7 *and later* but the version test
is too simple-minded:
Quote:

> Dim vers
> vers = iTunesApp.Version
> Dim Reg1
> Set Reg1 = new RegExp
> Reg1.Pattern = "^7"
> if Reg1.Test(vers) Then
> ' yay
> Else
> Wscript.Echo "This script requires iTunes 7"
> Wscript.Quit
> End If
The test only accepts version strings that start with "7"; it assumes
that other versions must be earlier. (BTW, similar simple-mindedness is
the same reason that Opera 10.00 identifies itself as "Opera/9.80" in
its browser identification string--scripts that just tested the first
digit of the version would decide that the current version is actually
version 1.)

This test worked fine when iTunes V7.0 was bright and shiny. If the
script is for your personal use only, you can just remove the test (and
cross your fingers whenever you update iTunes). If you intend to share
the script, you can make the version test smarter.

You can download the iTunes COM SDK from
http://developer.apple.com/sdk/itunescomsdk.html
(you might have to join the Apple Developers Club first).

--
Steve

Horse sense is the thing a horse has which keeps it from betting on
people. -W. C. Fields



My System SpecsSystem Spec
Old 4 Weeks Ago   #5 (permalink)
tonysathre


 
 

Re: iTunes script

Thanks a lot for the suggestions. I have already tried removing the
following, with no luck:
Quote:

> Dim vers
> vers = iTunesApp.Version
> Dim Reg1
> Set Reg1 = new RegExp
> Reg1.Pattern = "^7"
> if Reg1.Test(vers) Then
> ' yay
> Else
> Wscript.Echo "This script requires iTunes 7"
> Wscript.Quit
> End If
I have also tried changing this part: Reg1.Pattern = "^7" to 9, but it
didn't work either. Below is the error I get when running it with, or
without those changes.

(67, 1) Microsoft VBScript runtime error: ActiveX component can't
create object: 'iTunes.Application.1'

Thanks,

Tony
My System SpecsSystem Spec
Old 4 Weeks Ago   #6 (permalink)
Tom Lavedas


 
 

Re: iTunes script

On Oct 27, 6:12*pm, tonysathre <tonysat...@newsgroup> wrote:
Quote:

> Thanks a lot for the suggestions. I have already tried removing the
> following, with no luck:
>
Quote:

> > Dim vers
> > vers = iTunesApp.Version
> > Dim Reg1
> > Set Reg1 = new RegExp
> > Reg1.Pattern = "^7"
> > if Reg1.Test(vers) Then
> > ' yay
> > Else
> > Wscript.Echo "This script requires iTunes 7"
> > Wscript.Quit
> > End If
>
> I have also tried changing this part: Reg1.Pattern = "^7" to 9, but it
> didn't work either. Below is the error I get when running it with, or
> without those changes.
>
> (67, 1) Microsoft VBScript runtime error: ActiveX component can't
> create object: 'iTunes.Application.1'
>
> Thanks,
>
> Tony
You need to open the registry and search for iTunes and check for the
current version (the final number) to see if it has changed. Or you
can just try removing the number. That often, but no always, works.
________________
Tom Lavedas
My System SpecsSystem Spec
Old 4 Weeks Ago   #7 (permalink)
Alexander Mueller


 
 

Re: iTunes script

tonysathre schrieb:
Quote:

> Thanks a lot for the suggestions. I have already tried removing the
> following, with no luck:
>
Quote:

>> Dim vers
>> vers = iTunesApp.Version
>> Dim Reg1
>> Set Reg1 = new RegExp
>> Reg1.Pattern = "^7"
>> if Reg1.Test(vers) Then
>> ' yay
>> Else
>> Wscript.Echo "This script requires iTunes 7"
>> Wscript.Quit
>> End If
>
> I have also tried changing this part: Reg1.Pattern = "^7" to 9, but it
> didn't work either. Below is the error I get when running it with, or
> without those changes.
>
> (67, 1) Microsoft VBScript runtime error: ActiveX component can't
> create object: 'iTunes.Application.1'
Better use the version-independent ProgID, e.g.
'iTunes.Application'. If this still doesn't work then
ITunes isn't probably properly installed (or at least its COM-part)

As for the version check, the version-string returns sth like:
'8.1.0.52' (major.minor.revision.build), so you need the digits
before the first dot, which will be 2 digits soon, starting with
iTunes 10. If RegExp is the choice, a better pattern and numeric
check was:

Set Reg1 = new RegExp
Reg1.Pattern = "^(\d+?)\..+$"
Dim majorVer
majorVer = Reg1.Replace(iTunesApp.Version, "$1")
If Not IsNumeric(majorVer) Then
WSH.Echo "Error detecting iTunes-version"
WSH.Quit
ElseIf CInt(majorVer) < 7 Then
WSH.Echo "This scripts requires iTunes 7 or higher"
WSH.Quit
'Else 'Version OK
End If


HTH,
Alex

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
itunes corrupted .wmv files can't play with Media Player or itunes Vista music pictures video
Itunes has constant "itunes has stopped working" problem!! Vista music pictures video
once iTunes looses the input focus, the CDROM device disappears inthe iTunes application Vista General
installing itunes on vista...vbs script error!!! Vista General
iTunes authorization problem (iTunes 7.0.1.8, Vista build 5728) Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46