comitunesautohotkeyitunes-sdkitunesartwork

iTunes method SaveArtworkToFile failed, called from AutoHotkey COM object


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!


Solution

  • @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!