add deps to makefile fix gitignore remove deprecated ioutil (#3)
Co-authored-by: abs3nt <abs3nt@asdf.cafe> Reviewed-on: https://gitea.asdf.cafe/abs3nt/gospt/pulls/3 Co-authored-by: a <a@tuxpa.in> Co-committed-by: a <a@tuxpa.in>
This commit is contained in:
parent
e6ce4e3204
commit
673fa3f62f
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
bin/
|
bin/
|
||||||
gospt
|
bin/*
|
||||||
|
/gospt
|
||||||
|
9
Makefile
9
Makefile
@ -1,6 +1,8 @@
|
|||||||
build:
|
build: gospt
|
||||||
|
|
||||||
|
gospt: $(shell find . -name '*.go')
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
go build -o ./bin/gospt .
|
go build -o gospt .
|
||||||
|
|
||||||
completions:
|
completions:
|
||||||
mkdir -p completions
|
mkdir -p completions
|
||||||
@ -16,6 +18,7 @@ tidy:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf bin
|
rm -rf bin
|
||||||
|
rm -rf gospt
|
||||||
rm -rf completions
|
rm -rf completions
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@ -23,7 +26,7 @@ uninstall:
|
|||||||
rm /usr/share/zsh/site-functions/_gospt
|
rm /usr/share/zsh/site-functions/_gospt
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp bin/gospt /usr/bin
|
cp gospt /usr/bin
|
||||||
cp completions/_gospt /usr/share/zsh/site-functions/_gospt
|
cp completions/_gospt /usr/share/zsh/site-functions/_gospt
|
||||||
cp completions/gospt /usr/share/bash-completion/completions/gospt
|
cp completions/gospt /usr/share/bash-completion/completions/gospt
|
||||||
cp completions/gospt.fish /usr/share/fish/vendor_completions.d/gospt.fish
|
cp completions/gospt.fish /usr/share/fish/vendor_completions.d/gospt.fish
|
||||||
|
@ -3,7 +3,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -27,7 +27,6 @@ var (
|
|||||||
|
|
||||||
func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
||||||
if config.Values.ClientId == "" || config.Values.ClientSecret == "" || config.Values.Port == "" {
|
if config.Values.ClientId == "" || config.Values.ClientSecret == "" || config.Values.Port == "" {
|
||||||
configDir, _ := os.UserConfigDir()
|
|
||||||
fmt.Println("PLEASE WRITE YOUR CONFIG FILE IN", filepath.Join(configDir, "gospt/client.yml"))
|
fmt.Println("PLEASE WRITE YOUR CONFIG FILE IN", filepath.Join(configDir, "gospt/client.yml"))
|
||||||
fmt.Println("GO HERE TO AND MAKE AN APPLICATION: https://developer.spotify.com/dashboard/applications")
|
fmt.Println("GO HERE TO AND MAKE AN APPLICATION: https://developer.spotify.com/dashboard/applications")
|
||||||
fmt.Print("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"\nport:\"8888\"\n\n")
|
fmt.Print("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"\nport:\"8888\"\n\n")
|
||||||
@ -63,7 +62,7 @@ func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer authFile.Close()
|
defer authFile.Close()
|
||||||
authValue, err := ioutil.ReadAll(authFile)
|
authValue, err := io.ReadAll(authFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -82,7 +81,7 @@ func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(filepath.Join(configDir, "gospt/auth.json"), out, 0o644)
|
err = os.WriteFile(filepath.Join(configDir, "gospt/auth.json"), out, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("FAILED TO SAVE AUTH")
|
panic("FAILED TO SAVE AUTH")
|
||||||
}
|
}
|
||||||
@ -91,7 +90,7 @@ func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(filepath.Join(configDir, "gospt/auth.json"), out, 0o644)
|
err = os.WriteFile(filepath.Join(configDir, "gospt/auth.json"), out, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("FAILED TO SAVE AUTH")
|
panic("FAILED TO SAVE AUTH")
|
||||||
}
|
}
|
||||||
@ -138,7 +137,7 @@ func completeAuth(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(filepath.Join(configDir, "gospt/auth.json"), out, 0o644)
|
err = os.WriteFile(filepath.Join(configDir, "gospt/auth.json"), out, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("FAILED TO SAVE AUTH")
|
panic("FAILED TO SAVE AUTH")
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -728,7 +729,7 @@ func SetDevice(ctx *gctx.Context, client *spotify.Client, device spotify.PlayerD
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
configDir, _ := os.UserConfigDir()
|
configDir, _ := os.UserConfigDir()
|
||||||
err = ioutil.WriteFile(filepath.Join(configDir, "gospt/device.json"), out, 0o644)
|
err = os.WriteFile(filepath.Join(configDir, "gospt/device.json"), out, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -915,7 +916,7 @@ func activateDevice(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer deviceFile.Close()
|
defer deviceFile.Close()
|
||||||
deviceValue, err := ioutil.ReadAll(deviceFile)
|
deviceValue, err := io.ReadAll(deviceFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -936,35 +937,36 @@ func activateDevice(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
|
|
||||||
func GetRadioPlaylist(ctx *gctx.Context, client *spotify.Client) (*spotify.FullPlaylist, error) {
|
func GetRadioPlaylist(ctx *gctx.Context, client *spotify.Client) (*spotify.FullPlaylist, error) {
|
||||||
configDir, _ := os.UserConfigDir()
|
configDir, _ := os.UserConfigDir()
|
||||||
if _, err := os.Stat(filepath.Join(configDir, "gospt/radio.json")); err == nil {
|
playlistFile, err := os.ReadFile(filepath.Join(configDir, "gospt/radio.json"))
|
||||||
playlistFile, err := os.Open(filepath.Join(configDir, "gospt/radio.json"))
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
if err != nil {
|
return CreateRadioPlaylist(ctx, client)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer playlistFile.Close()
|
|
||||||
playlistValue, err := ioutil.ReadAll(playlistFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var playlist *spotify.FullPlaylist
|
|
||||||
err = json.Unmarshal(playlistValue, &playlist)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return playlist, nil
|
|
||||||
}
|
}
|
||||||
// private flag doesnt work
|
|
||||||
playlist, err := client.CreatePlaylistForUser(ctx, ctx.UserId, "autoradio", "Automanaged radio playlist", false, false)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out, err := json.MarshalIndent(playlist, "", " ")
|
var playlist *spotify.FullPlaylist
|
||||||
if err != nil {
|
err = json.Unmarshal(playlistFile, &playlist)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = ioutil.WriteFile(filepath.Join(configDir, "gospt/radio.json"), out, 0o644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return playlist, nil
|
return playlist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateRadioPlaylist(ctx *gctx.Context, client *spotify.Client) (*spotify.FullPlaylist, error) {
|
||||||
|
// private flag doesnt work
|
||||||
|
configDir, _ := os.UserConfigDir()
|
||||||
|
playlist, err := client.CreatePlaylistForUser(ctx, ctx.UserId, "autoradio", "Automanaged radio playlist", false, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
raw, err := json.MarshalIndent(playlist, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = os.WriteFile(filepath.Join(configDir, "gospt/radio.json"), raw, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlist, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user