Skip to content

Commit

Permalink
feat: get current track artwork
Browse files Browse the repository at this point in the history
Only for songs in library
  • Loading branch information
N0chteil committed May 27, 2023
1 parent e8af37d commit 90769d7
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/win32/wscript/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,37 @@ JSON || (JSON = {});
}
})();

var iTunes = WScript.CreateObject("iTunes.Application");
var iTunes = WScript.CreateObject("iTunes.Application"),
fileSystem = new ActiveXObject("Scripting.FileSystemObject");

var ITArtworkFormatUnknown = 0;
var ITArtworkFormatJPEG = 1;
var ITArtworkFormatPNG = 2;
var ITArtworkFormatBMP = 3;

function ArtworkFormatToFileExtension(artworkFormat) {
switch (artworkFormat) {
case ITArtworkFormatUnknown:
return ".unk";
break;

case ITArtworkFormatJPEG:
return ".jpg";
break;

case ITArtworkFormatPNG:
return ".png";
break;

case ITArtworkFormatBMP:
return ".bmp";
break;

default:
return ".unk";
break;
}
}

switch (WScript.arguments(0)) {
case "currentTrack":
Expand Down Expand Up @@ -69,6 +99,50 @@ switch (WScript.arguments(0)) {
}
break;

case "currentTrackArtwork":
var currentTrack = iTunes.currentTrack,
artworkFolder = WScript.arguments(1);

if (currentTrack.Artwork.Count === 0 || !artworkFolder) {
WScript.Echo(
encodeURI(
JSON.stringify({
artwork: undefined
})
)
);

break;
}

var currArtworks = currentTrack.Artwork,
numArtworks = currArtworks.Count,
artwork = currArtworks.Item(numArtworks),
artworkFileName;

if (!fileSystem.FolderExists(artworkFolder)) {
fileSystem.CreateFolder(artworkFolder);
}

artworkFolder = fileSystem.GetFolder(artworkFolder);
artworkFileName =
artworkFolder.Path +
"\\" +
"artwork" +
ArtworkFormatToFileExtension(artwork.Format);

artwork.SaveArtworkToFile(artworkFileName);

WScript.Echo(
encodeURI(
JSON.stringify({
artwork: artworkFileName
})
)
);

break;

case "playerState":
WScript.Echo(JSON.stringify(iTunes.PlayerState));
break;
Expand Down

0 comments on commit 90769d7

Please sign in to comment.