按名称以字母开头的艺术家计算 iTunes 歌曲的数量
Count number of iTunes songs by Artist with a name starting with a letter
我是 Applescript 的新手。我想要一个脚本来列出艺术家和该艺术家文件夹中的歌曲数量。我只想为名字以 A 开头的艺术家做这件事。当我准备好后,我会得到名字以 B 开头的艺术家的列表,依此类推。我确实找到了这个 post: "What's the fastest way in iOS to retrieve the number of songs for a specific artist?" 也许那个脚本可以工作,但我不知道如何修改这一行 "if (artistName != nil)" 以获得我想要的。另外,我不知道信息存储在哪里,所以我可以检索它“//存储新计数
[艺术家 setObject:[NSNumber numberWithInt:numSongs] forKey:artistName];哦,我没有使用 iOS,我将使用 osx。也许我可以修改我找到的这个脚本。它获取艺术家的专辑数量。
MPMediaQuery *albumQuery = [MPMediaQuery albumsQuery];
NSArray *albumCollection = [albumQuery collections];
NSCountedSet *artistAlbumCounter = [NSCountedSet set];
[albumCollection enumerateObjectsUsingBlock:^(MPMediaItemCollection *album, NSUInteger idx, BOOL *stop) {
NSString *artistName = [[album representativeItem] valueForProperty:MPMediaItemPropertyArtist];
[artistAlbumCounter addObject:artistName];
}];
NSLog(@"Artist Album Counted Set: %@", artistAlbumCounter);
感谢您提供的任何帮助。谢谢!
查看 iOS 代码和 ObjectiveC 以弄清楚您应该使用 Applescript 做什么是没有意义的!无论如何,这就是您想要的。
tell application "iTunes"
# Get playlist currently selected
set myPlayList to view of window 1
set s to (every track in myPlayList whose artist begins with "g")
repeat with t in s
log name of t
end repeat
log (count of s)
end tell
这个使用 selected playlist
(或者,如果由于某种原因失败,则使用整个库)并从 A
变为 Z
。用您的代码替换 log
部分。要查看它是如何工作的,请确保在 Script-Editor
中它显示 Log
并且为了更好地查看 select Messages
选项卡 。仅处理 file tracks
。
tell application "iTunes"
try
set selectedPlayList to view of window 1
on error
beep
set selectedPlayList to (container of browser window 1) -- whole library (I think)
end try
end tell
set totalItems to 0
repeat with i from (id of "A") to (id of "Z")
set thisLetter to (character id i)
log "-----------------------------------------------------------"
tell application "iTunes"
try
set currentItems to (file tracks in selectedPlayList whose artist begins with thisLetter)
set countItems to number of items in currentItems
set totalItems to totalItems + countItems
set s to "s"
if countItems = 1 then set s to ""
log (countItems as text) & " item" & s & " for artists starting with the letter " & quoted form of thisLetter
log "-----------------------------------------------------------"
repeat with i from 1 to countItems
set thisItem to item i of currentItems
tell thisItem -- this is like "tell file track x". Shortens the code because we can use "artist" instead of "artist of thisItem"
log (i as text) & ". " & quoted form of (get artist) & " | " & quoted form of (get name) & " [ " & time & " ] "
end tell
end repeat
on error the error_message number the error_number
beep
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
return
end try
end tell
end repeat
log "-----------------------------------------------------------"
log "Items: " & totalItems as text
我是 Applescript 的新手。我想要一个脚本来列出艺术家和该艺术家文件夹中的歌曲数量。我只想为名字以 A 开头的艺术家做这件事。当我准备好后,我会得到名字以 B 开头的艺术家的列表,依此类推。我确实找到了这个 post: "What's the fastest way in iOS to retrieve the number of songs for a specific artist?" 也许那个脚本可以工作,但我不知道如何修改这一行 "if (artistName != nil)" 以获得我想要的。另外,我不知道信息存储在哪里,所以我可以检索它“//存储新计数 [艺术家 setObject:[NSNumber numberWithInt:numSongs] forKey:artistName];哦,我没有使用 iOS,我将使用 osx。也许我可以修改我找到的这个脚本。它获取艺术家的专辑数量。
MPMediaQuery *albumQuery = [MPMediaQuery albumsQuery];
NSArray *albumCollection = [albumQuery collections];
NSCountedSet *artistAlbumCounter = [NSCountedSet set];
[albumCollection enumerateObjectsUsingBlock:^(MPMediaItemCollection *album, NSUInteger idx, BOOL *stop) {
NSString *artistName = [[album representativeItem] valueForProperty:MPMediaItemPropertyArtist];
[artistAlbumCounter addObject:artistName];
}];
NSLog(@"Artist Album Counted Set: %@", artistAlbumCounter);
感谢您提供的任何帮助。谢谢!
查看 iOS 代码和 ObjectiveC 以弄清楚您应该使用 Applescript 做什么是没有意义的!无论如何,这就是您想要的。
tell application "iTunes"
# Get playlist currently selected
set myPlayList to view of window 1
set s to (every track in myPlayList whose artist begins with "g")
repeat with t in s
log name of t
end repeat
log (count of s)
end tell
这个使用 selected playlist
(或者,如果由于某种原因失败,则使用整个库)并从 A
变为 Z
。用您的代码替换 log
部分。要查看它是如何工作的,请确保在 Script-Editor
中它显示 Log
并且为了更好地查看 select Messages
选项卡 。仅处理 file tracks
。
tell application "iTunes"
try
set selectedPlayList to view of window 1
on error
beep
set selectedPlayList to (container of browser window 1) -- whole library (I think)
end try
end tell
set totalItems to 0
repeat with i from (id of "A") to (id of "Z")
set thisLetter to (character id i)
log "-----------------------------------------------------------"
tell application "iTunes"
try
set currentItems to (file tracks in selectedPlayList whose artist begins with thisLetter)
set countItems to number of items in currentItems
set totalItems to totalItems + countItems
set s to "s"
if countItems = 1 then set s to ""
log (countItems as text) & " item" & s & " for artists starting with the letter " & quoted form of thisLetter
log "-----------------------------------------------------------"
repeat with i from 1 to countItems
set thisItem to item i of currentItems
tell thisItem -- this is like "tell file track x". Shortens the code because we can use "artist" instead of "artist of thisItem"
log (i as text) & ". " & quoted form of (get artist) & " | " & quoted form of (get name) & " [ " & time & " ] "
end tell
end repeat
on error the error_message number the error_number
beep
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
return
end try
end tell
end repeat
log "-----------------------------------------------------------"
log "Items: " & totalItems as text