2017-01-16 5 views
0

일부 아티스트의 인기 곡을 재생할 수있는 AppleScript을 만들려고합니다. ScriptEditor을 통해 iTunes 스크립트 라이브러리를 보았지만 나에게 유용한 것을 찾지 못했습니다. 이 사건이 가능하다면 누군가 나를 올바른 방향으로 인도 해주기를 바랍니다. 감사.AppleScript로 아티스트의 TOP 노래 재생

+0

"최고 곡"은 어떻게 정의합니까? 재생 횟수가 가장 많은 노래는 무엇입니까? –

+0

@ oa- 아이튠즈에 특별한 단락 "탑 노래"가 있습니다 –

답변

1

iTunes에서 트랙을 가져 오는 기본 방법은 get every track입니다. 예 :

tell application "iTunes" to set topTracks to every track of playlist "Library" whose artist is "Golden Earring" and rating is 100 

등급은 iTunes GUI에서 1 ~ 5 별 (또는 별 없음)이지만 백엔드에서는 0 ~ 100입니다. 백엔드 등급에 20을 곱하십시오 (또는 GUI 별표 수에 대해 백엔드 등급을 20으로 나눕니다). 0 별이 0과 같습니다.

iTunes에는 기발한 특징이 있습니다. and rating is 100을 추가하면 쉽게 하나 (아티스트)를 수행 한 다음 하드 (등급)를 수행하는 것보다 두 쿼리 모두에서 검색을 수행하는 것처럼 쿼리가 훨씬 느려집니다. 당신은 상단 X 노래를 의미하는 경우 "최고 노래"에 의해 지금

tell application "iTunes" 
    set artistTracks to every track of playlist "Library" whose artist is "Golden Earring" 
    set topTracks to {} 
    repeat with possibleTrack in artistTracks 
     if the rating of possibleTrack is 100 then copy possibleTrack to end of topTracks 
    end repeat 
end tell 

: 그 때문에, 이것은 아마도 특정 작가의 다섯 등급의 모든 트랙을 얻기에 훨씬 더 빨리, 많이있을 것입니다 그렇다면 충분한 등급 5 트랙이 x에 도달 할 것이라는 보장이 없기 때문에 특정 번 트랙의 번을 얻으려면 트랙 5 개를 잡고 충분히 갖고 있는지 확인해야합니다. 네 곡목을 평가하지 말고 4 곡을 가져 오는 등의 작업을 수행하는 방법에 대한 예가 있습니다. 더 많은 작업이 있습니다. 정확히 어떻게 "최고 곡"을 정의하는지에 따라 부분적으로 달라집니다.

때 목록은 아무도 일시 중지하거나 GUI의 트랙을 발전 것을 합리적으로 확신하는 경우, the duration of topTrack as number에 대한 지연이 포함될 수 있습니다 topTracks에서 다음 트랙으로 진행하는 선택을위한
tell application "iTunes" 
    set desiredArtist to "chi coltrane" 

    --get topCount tracks 
    set topCount to 5 
    set fiveStars to {} 
    set fourStars to {} 
    set threeStars to {} 
    set twoStars to {} 
    set oneStar to {} 
    set noStars to {} 
    set allTracks to every track of playlist "Library" whose artist is desiredArtist 

    --collect tracks into bins according to star rating 
    --this is much faster than doing five searches with "and rating is" 
    repeat with possibleTrack in allTracks 
     copy (rating of possibleTrack)/20 as integer to starRating 

     if starRating is 5 then 
      copy possibleTrack to end of fiveStars 
     else if starRating is 4 then 
      copy possibleTrack to end of fourStars 
     else if starRating is 3 then 
      copy possibleTrack to end of threeStars 
     else if starRating is 2 then 
      copy possibleTrack to end of twoStars 
     else if starRating is 1 then 
      copy possibleTrack to end of oneStars 
     else 
      copy possibleTrack to end of noStars 
     end if 
    end repeat 
end tell 

--collect the top tracks 
set topTracks to {} 
getTracks(fiveStars) 
getTracks(fourStars) 
getTracks(threeStars) 
getTracks(twoStars) 
getTracks(oneStar) 
getTracks(noStars) 

--play the tracks, if any 
if (count of topTracks) > 0 then 
    tell application "iTunes" 
     repeat with topTrack in topTracks 
      set topTrackID to the persistent ID of topTrack 
      play topTrack 
      --wait until this song is no longer playing, then go to the next 
      repeat while the persistent ID of current track is topTrackID 
       --delay a tenth of a second to avoid too much of the next random track 
       delay 0.1 
      end repeat 
     end repeat 
    end tell 
end if 

--add more tracks from the given trackList, until topCount is reached 
--within a list, the choice of which tracks to use to reach topCount is somewhat arbitrary 
on getTracks(trackList) 
    global topTracks, topCount 
    if (count of topTracks) ≥ topCount then return 
    repeat with possibleTrack in trackList 
     if (count of topTracks) ≥ topCount then 
      return 
     end if 
     copy possibleTrack to end of topTracks 
    end repeat 
end getTracks 

다른 옵션; 트랙 변경시 알림을 수신하는 핸들러를 설정할 수도 있습니다.

+0

이 큰 대답에 대해 매우 고마워요. 하지만 애플 뮤직리스트에서 내 라이브러리가 아닌 트랙을 얻을 수 있습니까? –

+0

나는 의심하지 않는다. 그러나 첫 번째 단계는 "일부 아티스트의 최고의 노래"가 의미하는 것을보다 명확하게 정의해야합니다. 즉, 노래가 "연주"되어야하는 기준은 무엇입니까? 이 예제에 도달하기 위해 취한 단계와 예제를 제공하는 데 도움이 될 수 있습니다. 일단 그렇게하면 iTunes를 사용하거나 다른 메커니즘을 사용하는 솔루션이 분명해질 수 있습니다. –

+0

iTunes에는 특별한 단락 "인기 곡"이 있으며이 목록을 가져오고 싶습니다. 그러나 일부 아티스트의 임의 곡 목록 만 얻을 수 있다면 좋을 것입니다. –