JScript to find broken tracks that iTunes can no longer find. Perfect for those who like to manage their large music libraries.
-
-
Save guilhermesimoes/687a180027cb67aeefe2 to your computer and use it in GitHub Desktop.
JScript: Find broken iTunes tracks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fso, iTunesApp; | |
/* global WScript, ActiveXObject, Enumerator */ | |
fso = new ActiveXObject("Scripting.FileSystemObject"); | |
iTunesApp = new ActiveXObject("iTunes.Application"); | |
outputResult(findBrokenTracks()); | |
function findBrokenTracks () { | |
var trackKindFile = 1, | |
brokenTracks = [], | |
tracksEnum, | |
track; | |
tracksEnum = new Enumerator(iTunesApp.LibraryPlaylist.Tracks); | |
while (!tracksEnum.atEnd()) { | |
track = tracksEnum.item(); | |
if (track.Kind == trackKindFile && track.Location === "") { | |
brokenTracks.push({ | |
name: track.Name, | |
artist: track.Artist | |
}); | |
} | |
tracksEnum.moveNext(); | |
} | |
return brokenTracks; | |
} | |
function outputResult (tracks) { | |
var numBrokenTracks; | |
numBrokenTracks = tracks.length; | |
if (numBrokenTracks > 0) { | |
writeToFile(tracks); | |
} | |
displayPopup(numBrokenTracks); | |
} | |
function writeToFile (tracks) { | |
var currentDir, outputPath, outputFile, track; | |
currentDir = fso.GetAbsolutePathName("."); | |
outputPath = fso.BuildPath(currentDir, "tracks.txt"); | |
outputFile = fso.CreateTextFile(outputPath, true, true); | |
for (var i=0; i<tracks.length; i++) { | |
track = tracks[i]; | |
outputFile.WriteLine(track.name + " by " + track.artist); | |
} | |
outputFile.Close(); | |
} | |
function displayPopup (numBrokenTracks) { | |
var message; | |
if (numBrokenTracks == 0) { | |
message = "No broken tracks were found!"; | |
} | |
else if (numBrokenTracks == 1) { | |
message = "There is 1 broken track."; | |
} | |
else { | |
message = "There are " + numBrokenTracks + " broken tracks."; | |
} | |
WScript.Echo(message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment