Last active
February 18, 2018 18:48
-
-
Save dnicolson/d89e2916c06c1c4e37263f011afe6b90 to your computer and use it in GitHub Desktop.
JXA script to find songs with incorrect sentence case
This file contains hidden or 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
const lowercaseWords = ['a', 'an', 'and', 'at', 'but', 'by', 'for', 'in', 'nor', 'of', 'on', 'or', 'so', 'the', 'to', 'with'] | |
.map(word => ` ${word.toLowerCase().replace(/(^| )(\w)/g, s => s.toUpperCase())} `).join('|') | |
const iTunes = Application('iTunes'), | |
selection = iTunes.selection() | |
let songsToFix = [] | |
selection.forEach((song) => { | |
const newName = song.name(), | |
newAlbum = song.album(), | |
newArtist = song.artist() | |
if (`${newName}${newAlbum}`.match(new RegExp(`^[0-9A-Z].*(${lowercaseWords})`))) { | |
songsToFix.push([newArtist, newAlbum]) | |
} | |
}) | |
const albumsToFix = [...new Set(songsToFix.map(o => JSON.stringify(o)))].map(s => JSON.parse(s)) | |
const destinationPlaylist = iTunes.sources[0].userPlaylists.whose({name: {_equals: 'Playlist'}}) | |
albumsToFix.forEach((album) => { | |
const songs = iTunes.playlists.whose({name: 'Library'})[0].tracks | |
.whose({artist: {_equals: album[0]}}) | |
.whose({album: {_equals: album[1]}}) | |
// songs.forEach((song) => { | |
// song.duplicate({to: destinationPlaylist[0]}) | |
// }) | |
for (let i=0; i<songs.length; i++) { | |
songs[i].duplicate({to: destinationPlaylist[0]}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment