Remove spotify
This commit is contained in:
parent
7ed6dcbcff
commit
efb316aacb
8 changed files with 9 additions and 160 deletions
|
@ -10,7 +10,4 @@ BUCKET_NAME=
|
||||||
AWS_REGION=
|
AWS_REGION=
|
||||||
AWS_ENDPOINT_URL_S3=
|
AWS_ENDPOINT_URL_S3=
|
||||||
AWS_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
SPOTIFY_CLIENT_ID=
|
|
||||||
SPOTIFY_CLIENT_SECRET=
|
|
||||||
SPOTIFY_REFRESH_TOKEN=
|
|
8
.vscode/extensions.json
vendored
Normal file
8
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"golang.go",
|
||||||
|
"bradlc.vscode-tailwindcss",
|
||||||
|
"redhat.vscode-yaml",
|
||||||
|
"a-h.templ"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,30 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"atri.dad/lib"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NowPlayingHandler(c echo.Context) error {
|
|
||||||
clientID := os.Getenv("SPOTIFY_CLIENT_ID")
|
|
||||||
clientSecret := os.Getenv("SPOTIFY_CLIENT_SECRET")
|
|
||||||
refreshToken := os.Getenv("SPOTIFY_REFRESH_TOKEN")
|
|
||||||
|
|
||||||
playing, err := lib.GetCurrentlyPlayingTrack(clientID, clientSecret, refreshToken)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(c.Response().Writer, err.Error(), http.StatusInternalServerError)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if playing.Item != nil && playing.Playing {
|
|
||||||
songName := lib.NowPlayingTextFilter(playing.Item.Name)
|
|
||||||
artistName := lib.NowPlayingTextFilter(playing.Item.Artists[0].Name)
|
|
||||||
|
|
||||||
return c.String(http.StatusOK, `<div class="indicator-item badge badge-success"><a _='on mouseover put "🔥 Listening to `+songName+" by "+artistName+` 🔥" into my.textContent on mouseout put "🔥" into my.textContent' href="`+playing.Item.ExternalURLs["spotify"]+`" rel="noreferrer" target="_blank">🔥</a></div>`)
|
|
||||||
} else {
|
|
||||||
return c.String(http.StatusOK, "")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,9 +21,6 @@ services:
|
||||||
- CLERK_SECRET_KEY=$CLERK_SECRET_KEY
|
- CLERK_SECRET_KEY=$CLERK_SECRET_KEY
|
||||||
- CLERK_WEBHOOK_SECRET=$CLERK_WEBHOOK_SECRET
|
- CLERK_WEBHOOK_SECRET=$CLERK_WEBHOOK_SECRET
|
||||||
- RESEND_API_KEY=$RESEND_API_KEY
|
- RESEND_API_KEY=$RESEND_API_KEY
|
||||||
- SPOTIFY_CLIENT_ID=$SPOTIFY_CLIENT_ID
|
|
||||||
- SPOTIFY_CLIENT_SECRET=$SPOTIFY_CLIENT_SECRET
|
|
||||||
- SPOTIFY_REFRESH_TOKEN=$SPOTIFY_REFRESH_TOKEN
|
|
||||||
- STRIPE_SECRET_KEY=$STRIPE_SECRET_KEY
|
- STRIPE_SECRET_KEY=$STRIPE_SECRET_KEY
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"atri.dad/lib/pubsub"
|
|
||||||
"github.com/zmb3/spotify"
|
|
||||||
"golang.org/x/oauth2"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
spotifyOAuth2Endpoint = oauth2.Endpoint{
|
|
||||||
TokenURL: "https://accounts.spotify.com/api/token",
|
|
||||||
AuthURL: "https://accounts.spotify.com/authorize",
|
|
||||||
}
|
|
||||||
config *oauth2.Config
|
|
||||||
once sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
func NowPlayingTextFilter(s string) string {
|
|
||||||
s = strings.Replace(s, "'", "'", -1)
|
|
||||||
s = strings.Replace(s, "\"", """, -1)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetOAuth2Config(clientID string, clientSecret string) *oauth2.Config {
|
|
||||||
once.Do(func() {
|
|
||||||
config = &oauth2.Config{
|
|
||||||
ClientID: clientID,
|
|
||||||
ClientSecret: clientSecret,
|
|
||||||
Scopes: []string{spotify.ScopeUserReadCurrentlyPlaying},
|
|
||||||
Endpoint: spotifyOAuth2Endpoint,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCurrentlyPlayingTrack(clientID string, clientSecret string, refreshToken string) (*spotify.CurrentlyPlaying, error) {
|
|
||||||
// OAuth2 config
|
|
||||||
config := GetOAuth2Config(clientID, clientSecret)
|
|
||||||
|
|
||||||
// Token source
|
|
||||||
tokenSource := config.TokenSource(context.Background(), &oauth2.Token{RefreshToken: refreshToken})
|
|
||||||
|
|
||||||
// Get new token
|
|
||||||
newToken, err := tokenSource.Token()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new client
|
|
||||||
client := spotify.Authenticator{}.NewClient(newToken)
|
|
||||||
|
|
||||||
// Get currently playing track
|
|
||||||
playing, err := client.PlayerCurrentlyPlaying()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return playing, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CurrentlyPlayingTrackSSE(ctx context.Context, pubSub pubsub.PubSub) error {
|
|
||||||
clientID := os.Getenv("SPOTIFY_CLIENT_ID")
|
|
||||||
clientSecret := os.Getenv("SPOTIFY_CLIENT_SECRET")
|
|
||||||
refreshToken := os.Getenv("SPOTIFY_REFRESH_TOKEN")
|
|
||||||
|
|
||||||
playing, err := GetCurrentlyPlayingTrack(clientID, clientSecret, refreshToken)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if playing.Item != nil && playing.Playing {
|
|
||||||
songName := NowPlayingTextFilter(playing.Item.Name)
|
|
||||||
artistName := NowPlayingTextFilter(playing.Item.Artists[0].Name)
|
|
||||||
|
|
||||||
return SendSSE(ctx, pubSub, "spotify", `<div class="indicator-item badge badge-success"><a _='on mouseover put "🔥 Listening to `+songName+" by "+artistName+` 🔥" into my.textContent on mouseout put "🔥" into my.textContent' href="`+playing.Item.ExternalURLs["spotify"]+`" rel="noreferrer" target="_blank">🔥</a></div>`)
|
|
||||||
} else {
|
|
||||||
SendSSE(ctx, pubSub, "spotify", "<span></span>")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
19
main.go
19
main.go
|
@ -88,31 +88,12 @@ func main() {
|
||||||
return api.SSEDemoSend(c, pubSub)
|
return api.SSEDemoSend(c, pubSub)
|
||||||
})
|
})
|
||||||
|
|
||||||
apiGroup.GET("/spotify/nowplaying", api.NowPlayingHandler)
|
|
||||||
apiGroup.POST("/tools/resize", api.ResizeHandler)
|
apiGroup.POST("/tools/resize", api.ResizeHandler)
|
||||||
|
|
||||||
// Webhook Routes:
|
// Webhook Routes:
|
||||||
webhookGroup := e.Group("/webhook")
|
webhookGroup := e.Group("/webhook")
|
||||||
webhookGroup.POST("/clerk", webhooks.ClerkWebhookHandler)
|
webhookGroup.POST("/clerk", webhooks.ClerkWebhookHandler)
|
||||||
|
|
||||||
// Spotify Polling
|
|
||||||
go func() {
|
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for range ticker.C {
|
|
||||||
// Check if there are any clients connected to the "spotify" channel
|
|
||||||
if lib.SSEServer.ClientCount("spotify") > 0 {
|
|
||||||
// Get the currently playing track
|
|
||||||
err := lib.CurrentlyPlayingTrackSSE(context.Background(), pubSub)
|
|
||||||
if err != nil {
|
|
||||||
// Handle error
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Parse command-line arguments for IP and port
|
// Parse command-line arguments for IP and port
|
||||||
ip := flag.String("ip", "", "IP address to bind the server to")
|
ip := flag.String("ip", "", "IP address to bind the server to")
|
||||||
port := flag.String("port", "3000", "Port to bind the server to")
|
port := flag.String("port", "3000", "Port to bind the server to")
|
||||||
|
|
|
@ -25,11 +25,6 @@ func Home(c echo.Context) error {
|
||||||
Href: "/api/rss",
|
Href: "/api/rss",
|
||||||
Icon: template.HTML(`<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H64zM96 136c0-13.3 10.7-24 24-24c137 0 248 111 248 248c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-110.5-89.5-200-200-200c-13.3 0-24-10.7-24-24zm0 96c0-13.3 10.7-24 24-24c83.9 0 152 68.1 152 152c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-57.4-46.6-104-104-104c-13.3 0-24-10.7-24-24zm0 120a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z"/></svg>`),
|
Icon: template.HTML(`<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H64zM96 136c0-13.3 10.7-24 24-24c137 0 248 111 248 248c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-110.5-89.5-200-200-200c-13.3 0-24-10.7-24-24zm0 96c0-13.3 10.7-24 24-24c83.9 0 152 68.1 152 152c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-57.4-46.6-104-104-104c-13.3 0-24-10.7-24-24zm0 120a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z"/></svg>`),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "Spotify",
|
|
||||||
Href: "https://open.spotify.com/user/31v3p4oq6im7fvpqhhbju222pbr4?si=f25bb92301434db2",
|
|
||||||
Icon: template.HTML(`<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" viewBox="0 0 496 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M248 8C111.1 8 0 119.1 0 256s111.1 248 248 248 248-111.1 248-248S384.9 8 248 8zm100.7 364.9c-4.2 0-6.8-1.3-10.7-3.6-62.4-37.6-135-39.2-206.7-24.5-3.9 1-9 2.6-11.9 2.6-9.7 0-15.8-7.7-15.8-15.8 0-10.3 6.1-15.2 13.6-16.8 81.9-18.1 165.6-16.5 237 26.2 6.1 3.9 9.7 7.4 9.7 16.5s-7.1 15.4-15.2 15.4zm26.9-65.6c-5.2 0-8.7-2.3-12.3-4.2-62.5-37-155.7-51.9-238.6-29.4-4.8 1.3-7.4 2.6-11.9 2.6-10.7 0-19.4-8.7-19.4-19.4s5.2-17.8 15.5-20.7c27.8-7.8 56.2-13.6 97.8-13.6 64.9 0 127.6 16.1 177 45.5 8.1 4.8 11.3 11 11.3 19.7-.1 10.8-8.5 19.5-19.4 19.5zm31-76.2c-5.2 0-8.4-1.3-12.9-3.9-71.2-42.5-198.5-52.7-280.9-29.7-3.6 1-8.1 2.6-12.9 2.6-13.2 0-23.3-10.3-23.3-23.6 0-13.6 8.4-21.3 17.4-23.9 35.2-10.3 74.6-15.2 117.5-15.2 73 0 149.5 15.2 205.4 47.8 7.8 4.5 12.9 10.7 12.9 22.6 0 13.6-11 23.3-23.2 23.3z"/></svg>`),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "Fediverse",
|
Name: "Fediverse",
|
||||||
Href: "https://blahaj.zone/@himbothy",
|
Href: "https://blahaj.zone/@himbothy",
|
||||||
|
|
|
@ -1,18 +1,5 @@
|
||||||
{{define "iconlinks"}}
|
{{define "iconlinks"}}
|
||||||
{{if eq .Name "Spotify"}}
|
|
||||||
<div class="indicator indicator-top indicator-end">
|
|
||||||
<div hx-ext="sse" sse-connect="/api/sse?channel=spotify" sse-swap="message">
|
|
||||||
<span class="link link-hover link-success" hx-get="/api/spotify/nowplaying" hx-trigger="load" hx-swap="self">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<a class="fill-white hover:fill-pink-500" href={{.Href}} target="_blank" rel="me" aria-label={{.Name}}>
|
|
||||||
{{.Icon}}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
{{else}}
|
|
||||||
<a class="fill-white hover:fill-pink-500" href={{.Href}} target="_blank" rel="me" aria-label={{.Name}}>
|
<a class="fill-white hover:fill-pink-500" href={{.Href}} target="_blank" rel="me" aria-label={{.Name}}>
|
||||||
{{.Icon}}
|
{{.Icon}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
Loading…
Add table
Reference in a new issue