/
lfm.go
58 lines (46 loc) · 1.72 KB
/
lfm.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
58
package main
import (
"flag"
"github.com/glava/lfm/config"
"github.com/glava/lfm/helper"
"github.com/glava/lfm/lastfm"
"strings"
)
func main() {
apiConfig := config.Load()
artistsFlag := flag.String("a", "", "artists names - separated by coma. Example: -a Drake,Kanye West")
userNames := flag.String("u", "", "last.fm user names comma separated")
limit := flag.Int("l", 20, "number of songs you want from artist. Default 20")
period := flag.String("p", "", "period you are searching for")
tags := flag.String("t", "", "last.fm tags")
playlist := flag.String("pl", "", "playlist")
flag.Parse()
//config.SaveToken(lastfm.FetchRequestToken(apiConfig))
//config.SaveSession(lastfm.FetchSession(apiConfig, config.GetToken()))
artists := append(strings.Split(*artistsFlag, ","), helper.ReadStdin()...)
//TODO: move go
if *artistsFlag != "" {
for _, artist := range artists {
if len(strings.TrimSpace(artist)) > 0 {
helper.Output(lastfm.ToTracks(<-lastfm.Get(lastfm.ArtistUrl(apiConfig.ApiKey, artist, *limit))), "")
}
}
}
if *userNames != "" {
for _, user := range strings.Split(*userNames, ",") {
helper.Output(lastfm.ToTracks(<-lastfm.Get(lastfm.UserUrl(apiConfig.ApiKey, user, *limit, *period))), user)
}
}
if *tags != "" {
for _, tag := range strings.Split(*tags, ",") {
helper.Output(lastfm.ToArtists(<-lastfm.Get(lastfm.TagUrl(apiConfig.ApiKey, tag, *limit))), "")
}
}
if *playlist != "" {
session := config.GetSession()
params := map[string]string{"method": "playlist.create", "title": *playlist, "api_key": apiConfig.ApiKey, "sk": session}
sig := lastfm.Signature(params, apiConfig.ApiSecret)
params["api_sig"] = sig
helper.Output(lastfm.ToPlaylist(<-lastfm.Post(params)), "")
}
}