尝试运行AppleScript以保持Trakt和iTunes“观看”状态同步

时间:2015-02-27 12:29:03

标签: macos applescript itunes

我有点像菜鸟,所以请不要介意我的无知。我已经搜索了几个小时试图定义和纠正我的一些错误,但现在我被卡住了,所以感谢您提供的任何帮助。

我找到了一个人写的脚本(https://github.com/olyckne/iTunesToTrakt),我试图运行它。他说用crontab运行它并使用类似

的东西

osascript iTunesToTrakt.applescript 1 apikey username sha1password

我尝试在终端中运行它,当然填写了正确的字段,但它说它找不到文件。

经过一番搜索,我找到了Lingon并且我每小时都在尝试运行脚本......这里是代码:

on run argv

    set interval to item 1 of argv as number
    set apiKey to item 2 of argv as string
    set username to item 3 of argv as string
    set pass to item 4 of argv as string
    set baseUrl to "http://api.trakt.tv/"
    set episodeUrl to baseUrl & "show/episode/seen/" & apiKey
    set movieUrl to baseUrl & "movie/seen/" & apiKey
    set currDate to current date
    set currDate to currDate - (interval * hours)
    set userPass to "{\"username\" : \"" & username & "\", \"password\" : \"" & pass & "\","
    set sendUrl to ""
    tell application "iTunes"
        set theLists to every playlist whose special kind is TV Shows or special kind is Movies
        repeat with theList in theLists
            set allTracks to (every track of theList whose played date > currDate)
            repeat with aTrack in allTracks
                set played to played date of aTrack
                set typeOfTrack to video kind of aTrack
                set theYear to year of aTrack
                if played > currDate then
                    if typeOfTrack = movie then
                        set sendUrl to movieUrl
                        set theMovieName to name of aTrack
                        set nrOfPlays to played count of aTrack
                        set lastPlayed to played date of aTrack
                        set lastPlayed to do shell script "date -j -f \"%A %d %B %Y %H:%M:%S\" \"" & lastPlayed & "\" +%s"
                        set sendData to userPass & "\"movies\" : [{\"title\" : \"" & theMovieName & "\", \"year\" : " & theYear & ", \"plays\" : " & nrOfPlays & ", \"last_played\" : " & lastPlayed & "}]"
                    else if typeOfTrack is TV show then
                        set sendUrl to episodeUrl
                        set theShow to show of aTrack
                        set theSeason to season number of aTrack
                        set theEpisode to episode number of aTrack
                        set sendData to userPass & "\"title\" : \"" & theShow & "\", \"year\" : " & theYear & ", \"episodes\" : [{ \"season\" : " & theSeason & ", \"episode\": " & theEpisode & "}]"

                    end if
                    set sendData to sendData & "}"

                    set cmd to "curl " & sendUrl & " -X POST --data '" & sendData & "' -H 'Content-type: application/json'"
                    tell me to do shell script cmd
                else
                    return "No new movies or TV show episodes watched." as string
                end if
            end repeat
        end repeat
    end tell
end run

(不确定为什么脚本不能正确格式化)我想的不是运行osascript命令我可以删除间隔行..并填写api,用户名和密码?这是正确的方向吗?脚本会这样工作吗?

谢谢你们!

0 个答案:

没有答案