CD対応
build and deploy / build (push) Successful in 2m5s
Details
build and deploy / build (push) Successful in 2m5s
Details
This commit is contained in:
parent
a6fc757571
commit
19dd003062
7
go.mod
7
go.mod
|
@ -1,9 +1,10 @@
|
|||
module now-playing
|
||||
|
||||
go 1.23
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.3
|
||||
|
||||
require (
|
||||
github.com/zmb3/spotify/v2 v2.4.3
|
||||
golang.org/x/oauth2 v0.24.0
|
||||
gopkg.in/ini.v1 v1.67.0
|
||||
golang.org/x/oauth2 v0.30.0
|
||||
)
|
||||
|
|
5
go.sum
5
go.sum
|
@ -83,6 +83,7 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
|
@ -206,6 +207,8 @@ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4Iltr
|
|||
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
|
||||
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
|
||||
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
@ -393,8 +396,6 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh
|
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
40
main.go
40
main.go
|
@ -33,7 +33,7 @@ func main() {
|
|||
).Client(ctx, token)
|
||||
client := spotify.New(httpClient)
|
||||
|
||||
lastId := ""
|
||||
lastId := "default"
|
||||
|
||||
for {
|
||||
playing, err := client.PlayerCurrentlyPlaying(ctx)
|
||||
|
@ -48,7 +48,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
if playing.Item.ID.String() == lastId {
|
||||
if playing.Item.ID.String() == lastId || playing.Item.Name == lastId {
|
||||
time.Sleep(30 * time.Second)
|
||||
continue
|
||||
}
|
||||
|
@ -56,23 +56,36 @@ func main() {
|
|||
lastId = playing.Item.ID.String()
|
||||
|
||||
builder := strings.Builder{}
|
||||
if lastId == "" {
|
||||
for _, artist := range playing.Item.Artists {
|
||||
builder.WriteString(artist.Name)
|
||||
builder.WriteString(",")
|
||||
}
|
||||
} else {
|
||||
for _, artist := range playing.Item.Artists {
|
||||
builder.WriteString("?[<plain>")
|
||||
builder.WriteString(artist.Name)
|
||||
builder.WriteString("</plain>](<https://open.spotify.com/artist/")
|
||||
builder.WriteString(artist.ID.String())
|
||||
builder.WriteString(">),")
|
||||
}
|
||||
}
|
||||
before, _ := strings.CutSuffix(builder.String(), ",")
|
||||
|
||||
for _, artist := range playing.Item.Artists {
|
||||
builder.WriteString("?[<plain>")
|
||||
builder.WriteString(artist.Name)
|
||||
builder.WriteString("</plain>](<https://open.spotify.com/artist/")
|
||||
builder.WriteString(artist.ID.String())
|
||||
builder.WriteString(">),")
|
||||
text := ""
|
||||
if lastId == "" {
|
||||
text = fmt.Sprintf("<plain>%s</plain>\\n<small>%s</small>", playing.Item.Name, before)
|
||||
lastId = playing.Item.Name
|
||||
} else {
|
||||
text = fmt.Sprintf("[<plain>%s</plain>](<https://open.spotify.com/track/%s>)\\n<small>%s</small>", playing.Item.Name, playing.Item.ID, before)
|
||||
}
|
||||
|
||||
before, _ := strings.CutSuffix(builder.String(), ",")
|
||||
text := fmt.Sprintf("[<plain>%s</plain>](<https://open.spotify.com/track/%s>)\\n<small>%s</small>", playing.Item.Name, playing.Item.ID, before)
|
||||
|
||||
body := fmt.Sprintf("{ \"visibility\" : \"home\", \"text\": \"%s\\n\\n#NowPlaying #usbharu_NowPlaying \"}", text)
|
||||
|
||||
log.Println(body)
|
||||
request, err := http.NewRequest("POST", endpoint, strings.NewReader(body))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
time.Sleep(10 * time.Minute)
|
||||
continue
|
||||
}
|
||||
request.Header.Add("Authorization", misskeyToken)
|
||||
|
@ -82,13 +95,14 @@ func main() {
|
|||
post, err := misskeyHttpClient.Do(request)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
time.Sleep(10 * time.Minute)
|
||||
continue
|
||||
}
|
||||
if post.StatusCode != 200 {
|
||||
log.Printf("Status is not 200. status: %d \n", post.StatusCode)
|
||||
time.Sleep(10 * time.Minute)
|
||||
continue
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Minute)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue