A way to send current playing track in cider to teal collection

Cider token support + README

Changed files
+64 -16
+2 -1
.gitignore
··· 1 - .vscode 1 + .vscode 2 + teal-cider
+1 -1
go.mod
··· 1 - module tealfm-cider 1 + module teal-cider 2 2 3 3 go 1.25.1 4 4
+39 -14
main.go
··· 4 4 "context" 5 5 "encoding/json" 6 6 "fmt" 7 + "io" 7 8 "net/http" 8 9 "os" 9 - "tealfm-cider/types" 10 + "teal-cider/types" 10 11 "time" 11 12 12 13 "github.com/bluesky-social/indigo/api/atproto" ··· 19 20 20 21 const AGENT string = "teal-cider/0.0.1" 21 22 23 + var ENV_DATA envData = envData{} 24 + 22 25 func getCurrentSong() types.NowPlaying { 23 26 r := types.NowPlaying{} 24 - res, err := http.DefaultClient.Get("http://localhost:10767/api/v1/playback/now-playing") 27 + req, err := http.NewRequest("GET", "http://localhost:10767/api/v1/playback/now-playing", nil) 25 28 if err != nil { 26 29 panic(err) 27 30 } 28 31 32 + ENV_DATA.AddCiderHeader(req) 33 + 34 + res, err := http.DefaultClient.Do(req) 35 + if err != nil { 36 + panic(err) 37 + } 38 + 39 + if res.StatusCode != 200 { 40 + b, err := io.ReadAll(res.Body) 41 + if err != nil { 42 + panic(err) 43 + } 44 + panic(string(b)) 45 + } 46 + 29 47 json.NewDecoder(res.Body).Decode(&r) 30 48 return r 31 49 } ··· 45 63 queryParam.Add("query", query) 46 64 queryParam.Add("fmt", "json") 47 65 req.URL.RawQuery = queryParam.Encode() 48 - 49 - fmt.Println(req.URL) 50 66 51 67 res, err := http.DefaultClient.Do(req) 52 68 if err != nil { ··· 109 125 } 110 126 } 111 127 112 - type LoginData struct { 113 - handle string 114 - password string 128 + type envData struct { 129 + handle string 130 + password string 131 + ciderToken string 115 132 } 116 133 117 - func getLoginData() LoginData { 118 - return LoginData{ 119 - handle: os.Getenv("HANDLE"), 120 - password: os.Getenv("PASSWORD"), 134 + func getEnvData() envData { 135 + return envData{ 136 + handle: os.Getenv("HANDLE"), 137 + password: os.Getenv("PASSWORD"), 138 + ciderToken: os.Getenv("CIDER_TOKEN"), 121 139 } 122 140 } 123 141 124 - func (l LoginData) Login() (*client.APIClient, error) { 142 + func (e envData) AddCiderHeader(r *http.Request) { 143 + if e.ciderToken != "" { 144 + r.Header.Add("apptoken", e.ciderToken) 145 + } 146 + } 147 + 148 + func (e envData) Login() (*client.APIClient, error) { 125 149 126 150 return client.LoginWithPassword( 127 151 context.Background(), 128 - identity.DefaultDirectory(), syntax.AtIdentifier{Inner: syntax.Handle(l.handle)}, l.password, "", nil) 152 + identity.DefaultDirectory(), syntax.AtIdentifier{Inner: syntax.Handle(e.handle)}, e.password, "", nil) 129 153 130 154 } 131 155 ··· 147 171 } 148 172 149 173 func main() { 150 - client, err := getLoginData().Login() 174 + ENV_DATA = getEnvData() 175 + client, err := ENV_DATA.Login() 151 176 if err != nil { 152 177 panic(err) 153 178 }
+22
readme.md
··· 1 + # Teal-Cider 2 + 3 + This is a tool that gets the current playing song on [Cider](cider.sh/) and makes a PDS Record for [teal.fm](https://teal.fm/) 4 + 5 + ## Requirements 6 + 7 + - Go 8 + - Cider 9 + - An ATProto Account 10 + 11 + ## Environment Variables 12 + 13 + - `HANDLE` : Your ATProto Handle [alice.bsky.social] 14 + - `PASSWORD` : An APP Password for your ATProto Account 15 + - `CIDER_TOKEN` : An APP_TOKEN from the Cider app [https://cider.sh/docs/client/rpc#authentication] 16 + 17 + ## Running 18 + 19 + ```sh 20 + $ go build . 21 + $ HANDLE="" PASSWORD="" CIDER_TOKEN="" ./teal-cider 22 + ```