-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrobble.go
57 lines (46 loc) · 1.04 KB
/
scrobble.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
"github.com/sonjek/go-lastfm/lastfm"
)
func getTrimmedString(r *bufio.Reader, msg string) (res string) {
fmt.Print(msg, ":")
res, _ = r.ReadString('\n')
res = strings.Trim(res, "\r\n")
return
}
func main() {
r := bufio.NewReader(os.Stdin)
apiKey := getTrimmedString(r, "API KEY")
apiSecret := getTrimmedString(r, "API SECRET")
api := lastfm.New(apiKey, apiSecret)
username := getTrimmedString(r, "Username")
password := getTrimmedString(r, "Password")
err := api.Login(username, password)
if err != nil {
fmt.Println(err)
return
}
artist := getTrimmedString(r, "Artist")
track := getTrimmedString(r, "Track")
p := lastfm.P{"artist": artist, "track": track}
_, err = api.Track.UpdateNowPlaying(p)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Updated Now-Playing.")
start := time.Now().Unix()
time.Sleep(35 * time.Second)
p["timestamp"] = start
_, err = api.Track.Scrobble(p)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Scrobbled.")
}