Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nozma/923832 to your computer and use it in GitHub Desktop.
Save nozma/923832 to your computer and use it in GitHub Desktop.
Last.fmのチャートをもとにプレイリスト(週間、3ヶ月、6ヶ月、12ヶ月、全期間で再生回数の多い曲)を作成する
-- 要XML Tools http://www.latenightsw.com/freeware/XMLTools2/
-- Last.fmユーザー名は適宜変更のこと
set username to "Rion778" -- Last.fm ユーザー名をセット
set max_playlist_length to 50 -- プレイリストの曲数の上限
set start_time to current date
set chart_filenames to {".LastFmChartWeekly", ".LastFmChartLast3months", ".LastFmChartLast6months", ".LastFmChartLast12months", ".LastFmChartToptracks"}
set chart_type to {"/weeklytrackchart", "/toptracks.xml?period=3month", "/toptracks.xml?period=6month", "/toptracks.xml?period=12month", "/toptracks.xml"}
set playlist_names to {"Last.fm - Weekly", "Last.fm - 3 months", "Last.fm - 6 months", "Last.fm - 12 months", "Last.fm - Overall"}
repeat with i from 1 to 5
do shell script "curl \"http://ws.audioscrobbler.com/2.0/user/" & username & (get item i of chart_type) & "\" -o ~/" & (get item i of chart_filenames)
set path_to_XML to get POSIX path of (path to home folder) & (get item i of chart_filenames)
set XMLdata to read POSIX file path_to_XML as «class utf8»
set theXML to parse XML XMLdata
set playlist_name to (get item i of playlist_names)
tell application "iTunes"
if name of every playlist contains playlist_name then
delete every track of playlist playlist_name
set thePlaylist to playlist playlist_name
else
set thePlaylist to make new playlist with properties {name:playlist_name}
end if
with timeout of 60 seconds
set n to 1
repeat with curItem in every item of XML contents of theXML
if (i = 1) then
set tmplist to (every track of playlist 1 whose artist contains item 1 of XML contents of item 1 of XML contents of curItem and name contains item 1 of XML contents of item 2 of XML contents of curItem)
else
set tmplist to (every track of playlist 1 whose artist contains XML contents of item 1 of XML contents of item 7 of XML contents of curItem and name contains item 1 of XML contents of item 1 of XML contents of curItem)
end if
if (tmplist is not {}) then duplicate (get item 1 of tmplist) to thePlaylist
set n to (n + 1)
if (n > max_playlist_length) then exit repeat
end repeat
end timeout
end tell
end repeat
-- do shell script "rm ~/.LastFmChart*" -- xmlファイルを消す場合はコメントアウト解除
display dialog "プレイリストの作成が終了しました。(" & (((current date) - start_time) as string) & "秒)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment