2015-04-05 51 views
0

我是Applescript的新手。我想要一个脚本来列出艺术家和该艺术家文件夹中的歌曲数量。我只想为名字以A开头的艺术家做这件事。当我准备好后,我会得到名字以B开头的艺术家名单,等等。我确实发现了这篇文章:“iOS中检索特定艺术家的歌曲数量的最快方法是什么?”也许这个脚本会工作,但我不知道如何修改这条线“if(artistName!= nil)”来获得我想要的。此外,我不知道信息的存储位置,所以我可以检索它“//存储新计数 [artists setObject:[NSNumber numberWithInt:numSongs] forKey:artistName];哦,我没有使用iOS我会是使用OSX。也许我可以修改这个剧本,我发现,它由艺术家得到专辑的数量。按歌手名字开头的iTunes歌曲数量以字母开头

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); 

我感谢所有帮助,您可以提供。谢谢!

回答

1

这是没有意义的看看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 
+0

谢谢Vic!正如你正确指出的那样,我不确定我在看什么。我绝对想要一个Applescript。 – 2015-04-05 20:50:25

+0

使用'set trackNames'(艺术家以“g”开头的myPlayList中的每个曲目的名称)''。如果您拥有大量的音轨,它将会更快,因为它可以通过单个命令获取所有信息,而不必为找到的每个音轨发送额外的Apple事件。 – foo 2015-04-06 18:37:39

+0

foo,代码看起来像这样吗? '告诉应用程序“iTunes”的 #获取播放当前选择 集myPlayList查看窗口1个 集tracknames到 日志(tracknames的计数) 结束(在myPlayList其艺术家开始用“克”每个轨道的名称)告诉' – 2015-04-09 19:11:10

1

这一个使用selected playlist(或者,如果由于某种原因失败,整个库),并从AZ。用您的代码替换log部件。要看它是如何工作的,请确保在Script-Editor它显示Log并为更好的视图选择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 
+0

这真棒!我害怕做A到Z(全部一次),因为有55,000首歌曲,我不知道需要多长时间。也许我可以调整它。 – 2015-04-06 04:42:59

+0

是的,只使用你想要的部分。在'tell thisItem'后面添加'如果我> 50然后退出重复' - block(在'end tell'之后)每个字母只做50个项目。但是......这并不是一个真正的好方法来查看所有曲目,因为不是以字母开头的艺术家名字会被错过,而以“The”开头的名字,比如“The Beatles”,都在“T”之下。 – 2015-04-06 06:52:24

+0

很酷。我认为披头士乐队(以及'The'开头的其他乐队)在'T'之下是奇怪的。苹果应该解决这个问题你不会在图书馆目录中看到这种情况,图书管理员很久以前就认识到这一点。 – 2015-04-06 15:21:37