Scrobble working!!! I mean, iTunes scrobble, not Last.FM (for now)

This commit is contained in:
Deluan
2016-03-11 20:49:01 -05:00
parent 329297dab8
commit d23f5ca635
8 changed files with 147 additions and 8 deletions
+31
View File
@@ -0,0 +1,31 @@
package itunesbridge
import (
"fmt"
"time"
)
type ItunesControl interface {
Scrobble(id string, playDate time.Time) error
}
func NewItunesControl() ItunesControl {
return itunesControl{}
}
type itunesControl struct{}
func (c itunesControl) Scrobble(id string, playDate time.Time) error {
script := Script{fmt.Sprintf(
`set theTrack to the first item of (every track whose database ID is equal to "%s")`, id),
`set c to (get played count of theTrack)`,
`tell theTrack`,
`set played count to c + 1`,
fmt.Sprintf(`set played date to date("%s")`, c.formatDateTime(playDate)),
`end tell`}
return script.Run()
}
func (c itunesControl) formatDateTime(d time.Time) string {
return d.Format("Jan _2, 2006 3:04PM")
}