-
-
Save technomorph/6e8d7fc36095d5f6056d58516e2e03ad to your computer and use it in GitHub Desktop.
プレイリスト名をコメントに入れる奴 var2.0
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
// 言語をjavascriptへ切り替えてご使用下さい | |
var app = Application.currentApplication() | |
app.includeStandardAdditions = true | |
// プレイリストのフォルダ情報を返す | |
function getParentPlaylist(playlist){ | |
try{ | |
return getParentPlaylist(playlist.parent()) + playlist.parent().name() + "/" | |
}catch(e){ | |
return "" | |
} | |
} | |
Progress.init = function(description,max){ | |
Progress.description = description | |
Progress.totalUnitCount = max | |
Progress.completedUnitCount = 0 | |
} | |
Progress.incriment = function(){ | |
Progress.completedUnitCount = Progress.completedUnitCount + 1 | |
} | |
var Tracks = {} // コメントを格納 | |
var comment = "" // 一時的なコメントを格納 | |
var iTunes = new Application("iTunes") // iTunesインスタンス | |
var iTunesTracks = iTunes.playlists().find(function(playlist){ | |
return playlist.specialKind() == "Music" | |
}).tracks() // 曲情報を格納 | |
// コメントからプレイリスト情報を消しながらコメントを取得 | |
Progress.init("コメントの取得中",iTunesTracks.length) | |
iTunesTracks.forEach(function(track){ | |
Progress.incriment() | |
Tracks[track.databaseID()] = track.comment().replace(/\n\$\$PlayList\$\$(.|\n)*$/m,'') + "\n$$PlayList$$" | |
}) | |
// プレイリストからコメントを追加 | |
iTunes.playlists().forEach(function(playlist){ | |
if(playlist.class() == "userPlaylist" && playlist.specialKind() == "none"){ | |
Progress.init("プレイリスト「" + playlist.name() + "」から曲情報を取得中",playlist.tracks().length) | |
comment = "\n" + getParentPlaylist(playlist) + playlist.name() + "," | |
playlist.tracks().forEach(function(track){ | |
Progress.incriment() | |
Tracks[track.databaseID()] += comment | |
}) | |
} | |
}) | |
// コメントを適用 | |
Progress.init("コメントを適用中",Object.keys(Tracks).length) | |
var error = 0 | |
var errorString = "" | |
iTunesTracks.forEach(function(track){ | |
if(Tracks[track.databaseID()] != undefined){ | |
Progress.incriment() | |
try{ | |
track.comment = Tracks[track.databaseID()] | |
}catch(e){ | |
Progress.description = "コメントを適用中 (エラー:" + ++error + "個)" | |
errorString += "\n" + track.name() | |
} | |
} | |
}) | |
if(!error.length){ | |
Progress.init("完了しました",0) | |
delay(3) | |
} else { | |
app.beep() | |
app.displayAlert( | |
"エラーが" + error.length + "件あります", | |
{ | |
message: "以下の保存に失敗しました"+errorString, | |
as: "critical", | |
buttons: '終了' | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment