iTunes method SaveArtworkToFile failed, called from AutoHotkey COM object

278 views Asked by At

I'm trying to extract the artwork file from my iTunes MP3 files using AutoHotkey (v1.1). The script works well until it gets to the SaveArtworkToFile method.

objITunesApp := ComObjCreate("iTunes.Application")
objLibrary := objITunesApp.Sources.Item(1)
objPlaylist := objLibrary.Playlists.ItemByName("! iTunesCovers")
objTracks := objPlaylist.Tracks
Loop, % objTracks.Count
{
    objTrack := objTracks.Item(A_Index)
    Loop, % objTrack.Artwork.Count
    {
        objArtwork := objTrack.Artwork.Item(A_Index)
        TrayTip, % "Track Index: " . objTrack.index
            , % "Artwork: " . A_Index . "/" . objTrack.Artwork.Count . "`n"
            . "Format: " . objArtwork.Format  . "`n"
            . "IsDownloadedArtwork: " . objArtwork.IsDownloadedArtwork  . "`n"
            . "Description: " . objArtwork.Description
        strFilePath := objTrack.index . "-" .  A_Index
        if (objArtwork.Format = 1)
            strExtension := "bmp"
        else if (objArtwork.Format = 2)
            strExtension := "jpg"
        else if (objArtwork.Format = 4)
            strExtension := "gif"
        else if (objArtwork.Format = 5)
            strExtension := "png"
        else
            strExtension := ""
        strResult := objArtwork.SaveArtworkToFile(strFilePath . "." . strExtension)
        MsgBox, % strFilePath . "." . strExtension . "`nResult: " . strResult
    }
}

I get this error message:

---------------------------
SaveArtworkToFile.ahk
---------------------------
Error:  0x8000FFFF - Défaillance irrémédiable

Source:     (null)
Description:    (null)
HelpFile:       (null)
HelpContext:    0

Specifically: SaveArtworkToFile

    Line#
--->    017: strResult := objArtwork.SaveArtworkToFile(strFilePath)
---------------------------

I have the same result with bpm and jpg file formats. And strResult returned by SaveArtworkToFile is empty. Should this method be supported by the AHK iTunes.Application COM object?

Thanks and Happy New Year!

2

There are 2 answers

0
JnLlnd On BEST ANSWER

@Manuell: Oh! Thanks for putting back the doc to my attention. In the

Parameters: filePath Full path to the artwork image file.

I missed the word "Full". In my script, I was relying on relative path. I just tested it with an absolute path and this work!

5
manuell On

Googled it for you: IITArtwork::SaveArtworkToFile

HRESULT IITArtwork::SaveArtworkToFile ( [in] BSTR filePath )
Save artwork data to an image file.

The format of the saved data is specified by the artwork's format (JPEG, PNG, or BMP). The directory that contains the file must already exist, it will not be created. If the file already exists, its contents will be replaced.

Parameters: filePath Full path to the artwork image file.

That method doen't return a value (as Hans said in comment). Try:

objArtwork.SaveArtworkToFile(strFilePath . "." . strExtension)