Merge pull request 'cache' (#10) from cache into main
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Reviewed-on: https://gitea.asdf.cafe/abs3nt/gospt/pulls/10
This commit is contained in:
abs3nt 2023-02-17 14:29:13 -08:00
commit ab4c9d4214
36 changed files with 573 additions and 441 deletions

9
go.mod
View File

@ -3,6 +3,7 @@ module gitea.asdf.cafe/abs3nt/gospt
go 1.19 go 1.19
require ( require (
gfx.cafe/util/go/frand v0.0.0-20230121041905-80dafb1e973e
github.com/atotto/clipboard v0.1.4 github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v0.14.0 github.com/charmbracelet/bubbles v0.14.0
github.com/charmbracelet/bubbletea v0.23.1 github.com/charmbracelet/bubbletea v0.23.1
@ -12,10 +13,12 @@ require (
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.6.1
github.com/zmb3/spotify/v2 v2.3.1 github.com/zmb3/spotify/v2 v2.3.1
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5
modernc.org/sqlite v1.20.3 modernc.org/sqlite v1.20.4
tuxpa.in/a/zlog v1.60.0
) )
require ( require (
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/containerd/console v1.0.3 // indirect github.com/containerd/console v1.0.3 // indirect
@ -25,6 +28,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect
@ -34,11 +38,12 @@ require (
github.com/muesli/termenv v0.13.0 // indirect github.com/muesli/termenv v0.13.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect
github.com/rs/zerolog v1.28.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/mod v0.3.0 // indirect golang.org/x/mod v0.3.0 // indirect
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78 // indirect golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78 // indirect

29
go.sum
View File

@ -31,8 +31,12 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gfx.cafe/util/go/frand v0.0.0-20230121041905-80dafb1e973e h1:A62zlsu3HkEAVRIb+cCpRIpSTmd047+ABV1KC2RsI2U=
gfx.cafe/util/go/frand v0.0.0-20230121041905-80dafb1e973e/go.mod h1:LNHxMJl0WnIr5+OChYxlVopxk+j7qxZv0XvWCzB6uGE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg= github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg=
@ -55,14 +59,16 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.4.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cristalhq/aconfig v0.17.0/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E= github.com/cristalhq/aconfig v0.17.0/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig v0.18.3 h1:Or12LIWIF+2mQpcGWA2PQnNc55+WiHFAqRjYh/pQNtM= github.com/cristalhq/aconfig v0.18.3 h1:Or12LIWIF+2mQpcGWA2PQnNc55+WiHFAqRjYh/pQNtM=
github.com/cristalhq/aconfig v0.18.3/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E= github.com/cristalhq/aconfig v0.18.3/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig/aconfigyaml v0.17.1 h1:xCCbRKVmKrft9gQj3gHOq6U5PduasvlXEIsxtyzmFZ0= github.com/cristalhq/aconfig/aconfigyaml v0.17.1 h1:xCCbRKVmKrft9gQj3gHOq6U5PduasvlXEIsxtyzmFZ0=
github.com/cristalhq/aconfig/aconfigyaml v0.17.1/go.mod h1:5DTsjHkvQ6hfbyxfG32roB1lF0U82rROtFaLxibL8V8= github.com/cristalhq/aconfig/aconfigyaml v0.17.1/go.mod h1:5DTsjHkvQ6hfbyxfG32roB1lF0U82rROtFaLxibL8V8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@ -72,6 +78,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@ -145,6 +152,9 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@ -168,6 +178,7 @@ github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0= github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0=
github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@ -177,6 +188,9 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
@ -186,8 +200,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@ -311,10 +325,13 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -486,8 +503,8 @@ modernc.org/memory v1.4.0 h1:crykUfNSnMAXaOJnnxcSzbUGMqkLWjklJKkBK2nwZwk=
modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sqlite v1.20.3 h1:SqGJMMxjj1PHusLxdYxeQSodg7Jxn9WWkaAQjKrntZs= modernc.org/sqlite v1.20.4 h1:J8+m2trkN+KKoE7jglyHYYYiaq5xmz2HoHJIiBlRzbE=
modernc.org/sqlite v1.20.3/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A= modernc.org/sqlite v1.20.4/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A=
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY= modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw= modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
modernc.org/tcl v1.15.0 h1:oY+JeD11qVVSgVvodMJsu7Edf8tr5E/7tuhF5cNYz34= modernc.org/tcl v1.15.0 h1:oY+JeD11qVVSgVvodMJsu7Edf8tr5E/7tuhF5cNYz34=
@ -497,3 +514,5 @@ modernc.org/z v1.7.0 h1:xkDw/KepgEjeizO2sNco+hqYkU12taxQFqPEmgm1GWE=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
tuxpa.in/a/zlog v1.60.0 h1:bU4wJk6nwvaFsKIvKKxgGM0uO+Z2kaE8LzgRiQ4NCRw=
tuxpa.in/a/zlog v1.60.0/go.mod h1:1t8SX1a4zLy+p6ylGn6m1ZXnssTPr/2ErdPjjSP+C2k=

98
src/cache/cache.go vendored Normal file
View File

@ -0,0 +1,98 @@
package cache
import (
"encoding/json"
"os"
"path/filepath"
"time"
"tuxpa.in/a/zlog/log"
)
type Cache struct {
Root string
}
type CacheEntry struct {
Expire time.Time `json:"e"`
Value string `json:"v"`
}
func DefaultCache() *Cache {
return &Cache{
Root: filepath.Join(os.TempDir(), "gospt.cache"),
}
}
func (c *Cache) load() (map[string]CacheEntry, error) {
out := map[string]CacheEntry{}
cache, err := os.Open(c.Root)
if err != nil {
return nil, err
}
if err := json.NewDecoder(cache).Decode(&out); err != nil {
return nil, err
}
return out, nil
}
func (c *Cache) save(m map[string]CacheEntry) error {
payload, err := json.Marshal(m)
if err != nil {
return err
}
log.Trace().Str("tosave", string(payload)).Msg("saving cache")
err = os.WriteFile(c.Root, payload, 0640)
if err != nil {
return err
}
return nil
}
func (c *Cache) GetOrDo(key string, do func() (string, error), ttl time.Duration) (string, error) {
conf, err := c.load()
if err != nil {
log.Trace().Err(err).Msg("cache failed read")
return c.Do(key, do, ttl)
}
val, ok := conf[key]
if !ok {
return c.Do(key, do, ttl)
}
if time.Now().After(val.Expire) {
return c.Do(key, do, ttl)
}
return val.Value, nil
}
func (c *Cache) Do(key string, do func() (string, error), ttl time.Duration) (string, error) {
if do == nil {
return "", nil
}
res, err := do()
if err != nil {
return "", err
}
return c.Put(key, res, ttl)
}
func (c *Cache) Put(key string, value string, ttl time.Duration) (string, error) {
conf, err := c.load()
if err != nil {
conf = map[string]CacheEntry{}
}
conf[key] = CacheEntry{
Expire: time.Now().Add(ttl),
Value: value,
}
log.Trace().Str("key", key).Str("val", value).Msg("saving new cache key")
err = c.save(conf)
if err != nil {
log.Trace().Err(err).Msg("cache failed save")
}
return value, nil
}
func (c *Cache) Clear() error {
return os.Remove(c.Root)
}

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,6 +13,6 @@ var clearRadioCmd = &cobra.Command{
Short: "Wipes the radio playlist and creates an empty one", Short: "Wipes the radio playlist and creates an empty one",
Long: `Wipes the radio playlist and creates an empty one, mostly for debugging or if something goes wrong`, Long: `Wipes the radio playlist and creates an empty one, mostly for debugging or if something goes wrong`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.ClearRadio(ctx, client) commands.ClearRadio(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,6 +13,6 @@ var devicesCmd = &cobra.Command{
Short: "Prints out devices", Short: "Prints out devices",
Long: `Prints out devices`, Long: `Prints out devices`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Devices(ctx, client) commands.Devices(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var likeCmd = &cobra.Command{
Short: "Likes song", Short: "Likes song",
Long: `Likes song`, Long: `Likes song`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Like(ctx, client) commands.Like(ctx)
}, },
} }

View File

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,7 +14,7 @@ var linkCmd = &cobra.Command{
Short: "Print link to currently playing song", Short: "Print link to currently playing song",
Long: `Print link to currently playing song`, Long: `Print link to currently playing song`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
link, err := commands.Link(ctx, client) link, err := commands.Link(ctx)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)

View File

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,7 +14,7 @@ var linkContextCmd = &cobra.Command{
Short: "Get url to current context(album, playlist)", Short: "Get url to current context(album, playlist)",
Long: `Get url to current context(album, playlist)`, Long: `Get url to current context(album, playlist)`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
link, err := commands.LinkContext(ctx, client) link, err := commands.LinkContext(ctx)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,7 +13,7 @@ var muteCmd = &cobra.Command{
Short: "mutes playback", Short: "mutes playback",
Long: `Mutes the spotify device, playback will continue`, Long: `Mutes the spotify device, playback will continue`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
err := commands.SetVolume(ctx, client, 0) err := commands.SetVolume(ctx, 0)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,8 +3,6 @@ package cmd
import ( import (
"strconv" "strconv"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -27,6 +25,6 @@ var nextCmd = &cobra.Command{
return err return err
} }
} }
return commands.Next(ctx, client, skipAmt) return commands.Next(ctx, skipAmt)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var nowPlayingCmd = &cobra.Command{
Short: "Shows song and artist of currently playing song", Short: "Shows song and artist of currently playing song",
Long: `Shows song and artist of currently playing song, useful for scripting`, Long: `Shows song and artist of currently playing song, useful for scripting`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.NowPlaying(ctx, client) commands.NowPlaying(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var pauseCmd = &cobra.Command{
Aliases: []string{"pa"}, Aliases: []string{"pa"},
Long: `Pauses currently playing song on spotify`, Long: `Pauses currently playing song on spotify`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Pause(ctx, client) commands.Pause(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var playCmd = &cobra.Command{
Short: "Plays spotify", Short: "Plays spotify",
Long: `Plays queued song on spotify, uses last used device and activates it if needed`, Long: `Plays queued song on spotify, uses last used device and activates it if needed`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Play(ctx, client) commands.Play(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var playurlCmd = &cobra.Command{
Args: cobra.MatchAll(cobra.ExactArgs(1)), Args: cobra.MatchAll(cobra.ExactArgs(1)),
Long: `Plays song from provided url`, Long: `Plays song from provided url`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.PlayUrl(ctx, client, args) commands.PlayUrl(ctx, args)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var previousCmd = &cobra.Command{
Short: "goes to previous song", Short: "goes to previous song",
Long: `if song is playing it will start over, if close to begining of song it will go to previous song`, Long: `if song is playing it will start over, if close to begining of song it will go to previous song`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Previous(ctx, client) commands.Previous(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var radioCmd = &cobra.Command{
Short: "Starts radio", Short: "Starts radio",
Long: `Starts radio`, Long: `Starts radio`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return commands.Radio(ctx, client) return commands.Radio(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var refillRadioCmd = &cobra.Command{
Short: "Refills the radio", Short: "Refills the radio",
Long: `Deletes all songs up to your position in the radio and adds that many songs to the end of the radio`, Long: `Deletes all songs up to your position in the radio and adds that many songs to the end of the radio`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return commands.RefillRadio(ctx, client) return commands.RefillRadio(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,6 +13,6 @@ var repeatCmd = &cobra.Command{
Short: "Toggles repeat", Short: "Toggles repeat",
Long: `Switches between repeating your current context or not, spotifyd does not support single track loops`, Long: `Switches between repeating your current context or not, spotifyd does not support single track loops`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Repeat(ctx, client) commands.Repeat(ctx)
}, },
} }

View File

@ -8,22 +8,24 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"gitea.asdf.cafe/abs3nt/gospt/src/auth" cmds "gitea.asdf.cafe/abs3nt/gospt/src/commands"
"gitea.asdf.cafe/abs3nt/gospt/src/config" "gitea.asdf.cafe/abs3nt/gospt/src/config"
"gitea.asdf.cafe/abs3nt/gospt/src/gctx" "gitea.asdf.cafe/abs3nt/gospt/src/gctx"
"tuxpa.in/a/zlog"
"github.com/cristalhq/aconfig" "github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigyaml" "github.com/cristalhq/aconfig/aconfigyaml"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/zmb3/spotify/v2"
) )
var ( var (
// Used for flags. // Used for flags.
ctx *gctx.Context ctx *gctx.Context
client *spotify.Client commands *cmds.Commands
cfgFile string cfgFile string
userLicense string userLicense string
verbose bool
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
Use: "gospt", Use: "gospt",
@ -45,27 +47,21 @@ func Execute(defCmd string) {
} }
func init() { func init() {
zlog.SetGlobalLevel(zlog.DebugLevel)
if len(os.Args) > 1 { if len(os.Args) > 1 {
if os.Args[1] == "completion" || os.Args[1] == "__complete" { if os.Args[1] == "completion" || os.Args[1] == "__complete" {
return return
} }
} }
cobra.OnInitialize(initConfig) rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
cobra.OnInitialize(initClient) cobra.OnInitialize(func() {
} if verbose {
zlog.SetGlobalLevel(zlog.TraceLevel)
func initClient() { }
var err error })
ctx = gctx.NewContext(context.Background()) ctx = gctx.NewContext(context.Background())
client, err = auth.GetClient(ctx) commands = &cmds.Commands{Context: ctx}
if err != nil { cobra.OnInitialize(initConfig)
panic(err)
}
currentUser, err := client.CurrentUser(ctx)
if err != nil {
panic(err)
}
ctx.UserId = currentUser.ID
} }
func initConfig() { func initConfig() {

View File

@ -3,8 +3,6 @@ package cmd
import ( import (
"strconv" "strconv"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -20,7 +18,7 @@ var seekCmd = &cobra.Command{
Long: `Seeks forward or backward, or seeks to a given position in seconds`, Long: `Seeks forward or backward, or seeks to a given position in seconds`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if args[0] == "forward" || args[0] == "f" { if args[0] == "forward" || args[0] == "f" {
err := commands.Seek(ctx, client, true) err := commands.Seek(ctx, true)
if err != nil { if err != nil {
return err return err
} }
@ -28,7 +26,7 @@ var seekCmd = &cobra.Command{
} }
if args[0] == "backward" || args[0] == "b" { if args[0] == "backward" || args[0] == "b" {
err := commands.Seek(ctx, client, false) err := commands.Seek(ctx, false)
if err != nil { if err != nil {
return err return err
} }
@ -40,7 +38,7 @@ var seekCmd = &cobra.Command{
return err return err
} }
pos = pos * 1000 pos = pos * 1000
err = commands.SetPosition(ctx, client, pos) err = commands.SetPosition(ctx, pos)
if err != nil { if err != nil {
return err return err
} }

View File

@ -15,6 +15,6 @@ var setDeviceCmd = &cobra.Command{
Short: "Shows tui to pick active device", Short: "Shows tui to pick active device",
Long: `Allows setting or changing the active spotify device, shown in a tui`, Long: `Allows setting or changing the active spotify device, shown in a tui`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
tui.StartTea(ctx, client, "devices") tui.StartTea(ctx, commands, "devices")
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,6 +13,6 @@ var shuffleCmd = &cobra.Command{
Short: "Toggles shuffle", Short: "Toggles shuffle",
Long: `Enables shuffle if it is currently disabled or disables it if it is currently active`, Long: `Enables shuffle if it is currently disabled or disables it if it is currently active`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Shuffle(ctx, client) commands.Shuffle(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,6 +13,6 @@ var statusCmd = &cobra.Command{
Short: "Returns player status in json", Short: "Returns player status in json",
Long: `Returns all player status in json, useful for scripting`, Long: `Returns all player status in json, useful for scripting`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Status(ctx, client) commands.Status(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var togglePlayCmd = &cobra.Command{
Short: "Toggles the play state of spotify", Short: "Toggles the play state of spotify",
Long: `If you are playing a song it will pause and if a song is paused it will play`, Long: `If you are playing a song it will pause and if a song is paused it will play`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.TogglePlay(ctx, client) commands.TogglePlay(ctx)
}, },
} }

View File

@ -4,7 +4,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"gitea.asdf.cafe/abs3nt/gospt/src/tui" "gitea.asdf.cafe/abs3nt/gospt/src/tui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -20,12 +19,12 @@ var tracksCmd = &cobra.Command{
Long: `Uses TUI to open a list of saved tracks`, Long: `Uses TUI to open a list of saved tracks`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
configDir, _ := os.UserConfigDir() configDir, _ := os.UserConfigDir()
if commands.ActiveDeviceExists(ctx, client) { if commands.ActiveDeviceExists(ctx) {
return tui.StartTea(ctx, client, "tracks") return tui.StartTea(ctx, commands, "tracks")
} }
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
return tui.StartTea(ctx, client, "devices") return tui.StartTea(ctx, commands, "devices")
} }
return tui.StartTea(ctx, client, "tracks") return tui.StartTea(ctx, commands, "tracks")
}, },
} }

View File

@ -4,7 +4,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"gitea.asdf.cafe/abs3nt/gospt/src/tui" "gitea.asdf.cafe/abs3nt/gospt/src/tui"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -20,12 +19,12 @@ var tuiCmd = &cobra.Command{
Long: `Default command. this is what will run if no other commands are present. Shows the main menu.`, Long: `Default command. this is what will run if no other commands are present. Shows the main menu.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
configDir, _ := os.UserConfigDir() configDir, _ := os.UserConfigDir()
if commands.ActiveDeviceExists(ctx, client) { if commands.ActiveDeviceExists(ctx) {
return tui.StartTea(ctx, client, "main") return tui.StartTea(ctx, commands, "main")
} }
if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil {
return tui.StartTea(ctx, client, "devices") return tui.StartTea(ctx, commands, "devices")
} }
return tui.StartTea(ctx, client, "main") return tui.StartTea(ctx, commands, "main")
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -16,6 +14,6 @@ var unlikeCmd = &cobra.Command{
Short: "unlikes song", Short: "unlikes song",
Long: `unlikes song`, Long: `unlikes song`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
commands.Unlike(ctx, client) commands.Unlike(ctx)
}, },
} }

View File

@ -1,8 +1,6 @@
package cmd package cmd
import ( import (
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,7 +13,7 @@ var unmuteCmd = &cobra.Command{
Short: "unmutes playback", Short: "unmutes playback",
Long: `unmutes the spotify device, playback will continue`, Long: `unmutes the spotify device, playback will continue`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
err := commands.SetVolume(ctx, client, 100) err := commands.SetVolume(ctx, 100)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,8 +3,6 @@ package cmd
import ( import (
"strconv" "strconv"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -20,7 +18,7 @@ var volumeCmd = &cobra.Command{
Long: `Sets the volume to the given percent [0-100] or increases/decreases by 5 percent if you say up or down`, Long: `Sets the volume to the given percent [0-100] or increases/decreases by 5 percent if you say up or down`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if args[0] == "up" { if args[0] == "up" {
err := commands.ChangeVolume(ctx, client, 5) err := commands.ChangeVolume(ctx, 5)
if err != nil { if err != nil {
return err return err
} }
@ -28,7 +26,7 @@ var volumeCmd = &cobra.Command{
} }
if args[0] == "down" { if args[0] == "down" {
err := commands.ChangeVolume(ctx, client, -5) err := commands.ChangeVolume(ctx, -5)
if err != nil { if err != nil {
return err return err
} }
@ -39,7 +37,7 @@ var volumeCmd = &cobra.Command{
if err != nil { if err != nil {
return err return err
} }
err = commands.SetVolume(ctx, client, vol) err = commands.SetVolume(ctx, vol)
if err != nil { if err != nil {
return err return err
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,23 +2,32 @@ package gctx
import ( import (
"context" "context"
"log" "fmt"
"os" "os"
"tuxpa.in/a/zlog"
) )
type Context struct { type Context struct {
zlog.Logger
Debug zlog.Logger
context.Context context.Context
*log.Logger }
Debug *log.Logger
UserId string func (c *Context) Err() error {
return c.Context.Err()
}
func (c *Context) Println(args ...any) {
c.Info().Msg(fmt.Sprint(args...))
} }
func NewContext(ctx context.Context) *Context { func NewContext(ctx context.Context) *Context {
out := &Context{ out := &Context{
ctx, Context: ctx,
log.New(os.Stdout, "LOG:", 0), Logger: zlog.New(os.Stderr),
log.New(os.Stdout, "DEBUG:", 1), Debug: zlog.New(os.Stderr),
"",
} }
return out return out
} }

View File

@ -7,95 +7,95 @@ import (
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )
func HandlePlayWithContext(ctx *gctx.Context, client *spotify.Client, uri *spotify.URI, pos int) { func HandlePlayWithContext(ctx *gctx.Context, commands *commands.Commands, uri *spotify.URI, pos int) {
var err error var err error
err = commands.PlaySongInPlaylist(ctx, client, uri, pos) err = commands.PlaySongInPlaylist(ctx, uri, pos)
if err != nil { if err != nil {
return return
} }
} }
func HandleRadio(ctx *gctx.Context, client *spotify.Client, song spotify.SimpleTrack) { func HandleRadio(ctx *gctx.Context, commands *commands.Commands, song spotify.SimpleTrack) {
err := commands.RadioGivenSong(ctx, client, song, 0) err := commands.RadioGivenSong(ctx, song, 0)
if err != nil { if err != nil {
return return
} }
} }
func HandleAlbumRadio(ctx *gctx.Context, client *spotify.Client, album spotify.SimpleAlbum) { func HandleAlbumRadio(ctx *gctx.Context, commands *commands.Commands, album spotify.SimpleAlbum) {
err := commands.RadioFromAlbum(ctx, client, album) err := commands.RadioFromAlbum(ctx, album)
if err != nil { if err != nil {
return return
} }
} }
func HandleSeek(ctx *gctx.Context, client *spotify.Client, fwd bool) { func HandleSeek(ctx *gctx.Context, commands *commands.Commands, fwd bool) {
err := commands.Seek(ctx, client, fwd) err := commands.Seek(ctx, fwd)
if err != nil { if err != nil {
return return
} }
} }
func HandleVolume(ctx *gctx.Context, client *spotify.Client, up bool) { func HandleVolume(ctx *gctx.Context, commands *commands.Commands, up bool) {
vol := 10 vol := 10
if !up { if !up {
vol = -10 vol = -10
} }
err := commands.ChangeVolume(ctx, client, vol) err := commands.ChangeVolume(ctx, vol)
if err != nil { if err != nil {
return return
} }
} }
func HandleArtistRadio(ctx *gctx.Context, client *spotify.Client, artist spotify.SimpleArtist) { func HandleArtistRadio(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) {
err := commands.RadioGivenArtist(ctx, client, artist) err := commands.RadioGivenArtist(ctx, artist)
if err != nil { if err != nil {
return return
} }
} }
func HandleAlbumArtist(ctx *gctx.Context, client *spotify.Client, artist spotify.SimpleArtist) { func HandleAlbumArtist(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) {
err := commands.RadioGivenArtist(ctx, client, artist) err := commands.RadioGivenArtist(ctx, artist)
if err != nil { if err != nil {
return return
} }
} }
func HandlePlaylistRadio(ctx *gctx.Context, client *spotify.Client, playlist spotify.SimplePlaylist) { func HandlePlaylistRadio(ctx *gctx.Context, commands *commands.Commands, playlist spotify.SimplePlaylist) {
err := commands.RadioFromPlaylist(ctx, client, playlist) err := commands.RadioFromPlaylist(ctx, playlist)
if err != nil { if err != nil {
return return
} }
} }
func HandleLibraryRadio(ctx *gctx.Context, client *spotify.Client) { func HandleLibraryRadio(ctx *gctx.Context, commands *commands.Commands) {
err := commands.RadioFromSavedTracks(ctx, client) err := commands.RadioFromSavedTracks(ctx)
if err != nil { if err != nil {
return return
} }
} }
func HandlePlayLikedSong(ctx *gctx.Context, client *spotify.Client, position int) { func HandlePlayLikedSong(ctx *gctx.Context, commands *commands.Commands, position int) {
err := commands.PlayLikedSongs(ctx, client, position) err := commands.PlayLikedSongs(ctx, position)
if err != nil { if err != nil {
return return
} }
} }
func HandlePlayTrack(ctx *gctx.Context, client *spotify.Client, track spotify.ID) { func HandlePlayTrack(ctx *gctx.Context, commands *commands.Commands, track spotify.ID) {
err := commands.QueueSong(ctx, client, track) err := commands.QueueSong(ctx, track)
if err != nil { if err != nil {
return return
} }
err = commands.Next(ctx, client, 1) err = commands.Next(ctx, 1)
if err != nil { if err != nil {
return return
} }
} }
func HandleSetDevice(ctx *gctx.Context, client *spotify.Client, player spotify.PlayerDevice) { func HandleSetDevice(ctx *gctx.Context, commands *commands.Commands, player spotify.PlayerDevice) {
var err error var err error
err = commands.SetDevice(ctx, client, player) err = commands.SetDevice(ctx, player)
if err != nil { if err != nil {
return return
} }

View File

@ -4,15 +4,13 @@ import (
"fmt" "fmt"
"time" "time"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
) )
func (m *mainModel) LoadMoreItems() { func (m *mainModel) LoadMoreItems() {
switch m.mode { switch m.mode {
case "artist": case "artist":
albums, err := commands.ArtistAlbums(m.ctx, m.client, m.artist.ID, (page + 1)) albums, err := m.commands.ArtistAlbums(m.ctx, m.artist.ID, (page + 1))
page++ page++
if err != nil { if err != nil {
return return
@ -32,7 +30,7 @@ func (m *mainModel) LoadMoreItems() {
main_updates <- m main_updates <- m
return return
case "artists": case "artists":
artists, err := commands.UserArtists(m.ctx, m.client, (page + 1)) artists, err := m.commands.UserArtists(m.ctx, (page + 1))
page++ page++
if err != nil { if err != nil {
return return
@ -52,7 +50,7 @@ func (m *mainModel) LoadMoreItems() {
main_updates <- m main_updates <- m
return return
case "album": case "album":
tracks, err := commands.AlbumTracks(m.ctx, m.client, m.album.ID, (page + 1)) tracks, err := m.commands.AlbumTracks(m.ctx, m.album.ID, (page + 1))
page++ page++
if err != nil { if err != nil {
return return
@ -73,7 +71,7 @@ func (m *mainModel) LoadMoreItems() {
main_updates <- m main_updates <- m
return return
case "albums": case "albums":
albums, err := commands.UserAlbums(m.ctx, m.client, (page + 1)) albums, err := m.commands.UserAlbums(m.ctx, (page + 1))
page++ page++
if err != nil { if err != nil {
return return
@ -93,7 +91,7 @@ func (m *mainModel) LoadMoreItems() {
main_updates <- m main_updates <- m
return return
case "main": case "main":
playlists, err := commands.Playlists(m.ctx, m.client, (page + 1)) playlists, err := m.commands.Playlists(m.ctx, (page + 1))
page++ page++
if err != nil { if err != nil {
return return
@ -112,7 +110,7 @@ func (m *mainModel) LoadMoreItems() {
main_updates <- m main_updates <- m
return return
case "playlist": case "playlist":
tracks, err := commands.PlaylistTracks(m.ctx, m.client, m.playlist.ID, (page + 1)) tracks, err := m.commands.PlaylistTracks(m.ctx, m.playlist.ID, (page + 1))
page++ page++
if err != nil { if err != nil {
return return
@ -133,7 +131,7 @@ func (m *mainModel) LoadMoreItems() {
main_updates <- m main_updates <- m
return return
case "tracks": case "tracks":
tracks, err := commands.TrackList(m.ctx, m.client, (page + 1)) tracks, err := m.commands.TrackList(m.ctx, (page + 1))
page++ page++
if err != nil { if err != nil {
return return

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"time" "time"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"gitea.asdf.cafe/abs3nt/gospt/src/gctx" "gitea.asdf.cafe/abs3nt/gospt/src/gctx"
"github.com/atotto/clipboard" "github.com/atotto/clipboard"
@ -74,7 +75,7 @@ type mainModel struct {
list list.Model list list.Model
input textinput.Model input textinput.Model
ctx *gctx.Context ctx *gctx.Context
client *spotify.Client commands *commands.Commands
mode Mode mode Mode
playlist spotify.SimplePlaylist playlist spotify.SimplePlaylist
artist spotify.SimpleArtist artist spotify.SimpleArtist
@ -91,34 +92,34 @@ func (m *mainModel) PlayRadio() {
selectedItem := m.list.SelectedItem().(mainItem).SpotifyItem selectedItem := m.list.SelectedItem().(mainItem).SpotifyItem
switch selectedItem.(type) { switch selectedItem.(type) {
case spotify.SimplePlaylist: case spotify.SimplePlaylist:
go HandlePlaylistRadio(m.ctx, m.client, selectedItem.(spotify.SimplePlaylist)) go HandlePlaylistRadio(m.ctx, m.commands, selectedItem.(spotify.SimplePlaylist))
return return
case *spotify.SavedTrackPage: case *spotify.SavedTrackPage:
go HandleLibraryRadio(m.ctx, m.client) go HandleLibraryRadio(m.ctx, m.commands)
return return
case spotify.SimpleAlbum: case spotify.SimpleAlbum:
go HandleAlbumRadio(m.ctx, m.client, selectedItem.(spotify.SimpleAlbum)) go HandleAlbumRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleAlbum))
return return
case spotify.FullAlbum: case spotify.FullAlbum:
go HandleAlbumRadio(m.ctx, m.client, selectedItem.(spotify.FullAlbum).SimpleAlbum) go HandleAlbumRadio(m.ctx, m.commands, selectedItem.(spotify.FullAlbum).SimpleAlbum)
return return
case spotify.SimpleArtist: case spotify.SimpleArtist:
go HandleArtistRadio(m.ctx, m.client, selectedItem.(spotify.SimpleArtist)) go HandleArtistRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleArtist))
return return
case spotify.FullArtist: case spotify.FullArtist:
go HandleArtistRadio(m.ctx, m.client, selectedItem.(spotify.FullArtist).SimpleArtist) go HandleArtistRadio(m.ctx, m.commands, selectedItem.(spotify.FullArtist).SimpleArtist)
return return
case spotify.SimpleTrack: case spotify.SimpleTrack:
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.SimpleTrack)) go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.SimpleTrack))
return return
case spotify.FullTrack: case spotify.FullTrack:
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.FullTrack).SimpleTrack) go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.FullTrack).SimpleTrack)
return return
case spotify.PlaylistTrack: case spotify.PlaylistTrack:
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.PlaylistTrack).Track.SimpleTrack) go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.PlaylistTrack).Track.SimpleTrack)
return return
case spotify.SavedTrack: case spotify.SavedTrack:
go HandleRadio(m.ctx, m.client, selectedItem.(spotify.SavedTrack).SimpleTrack) go HandleRadio(m.ctx, m.commands, selectedItem.(spotify.SavedTrack).SimpleTrack)
return return
} }
} }
@ -129,34 +130,34 @@ func (m *mainModel) GoBack() (tea.Cmd, error) {
return tea.Quit, nil return tea.Quit, nil
case Albums, Artists, Tracks, Playlist, Devices, Search: case Albums, Artists, Tracks, Playlist, Devices, Search:
m.mode = Main m.mode = Main
new_items, err := MainView(m.ctx, m.client) new_items, err := MainView(m.ctx, m.commands)
if err != nil { if err != nil {
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case Album: case Album:
m.mode = Albums m.mode = Albums
new_items, err := AlbumsView(m.ctx, m.client) new_items, err := AlbumsView(m.ctx, m.commands)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case Artist: case Artist:
m.mode = Artists m.mode = Artists
new_items, err := ArtistsView(m.ctx, m.client) new_items, err := ArtistsView(m.ctx, m.commands)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case ArtistAlbum: case ArtistAlbum:
m.mode = Artist m.mode = Artist
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists: case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists:
m.mode = Search m.mode = Search
items, result, err := SearchView(m.ctx, m.client, m.search) items, result, err := SearchView(m.ctx, m.commands, m.search)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -164,28 +165,28 @@ func (m *mainModel) GoBack() (tea.Cmd, error) {
m.list.SetItems(items) m.list.SetItems(items)
case SearchArtist: case SearchArtist:
m.mode = SearchArtists m.mode = SearchArtists
new_items, err := SearchArtistsView(m.ctx, m.client, m.searchResults.Artists) new_items, err := SearchArtistsView(m.ctx, m.commands, m.searchResults.Artists)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case SearchArtistAlbum: case SearchArtistAlbum:
m.mode = SearchArtist m.mode = SearchArtist
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case SearchAlbum: case SearchAlbum:
m.mode = SearchAlbums m.mode = SearchAlbums
new_items, err := SearchAlbumsView(m.ctx, m.client, m.searchResults.Albums) new_items, err := SearchAlbumsView(m.ctx, m.commands, m.searchResults.Albums)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
case SearchPlaylist: case SearchPlaylist:
m.mode = SearchPlaylists m.mode = SearchPlaylists
new_items, err := SearchPlaylistsView(m.ctx, m.client, m.searchResults.Playlists) new_items, err := SearchPlaylistsView(m.ctx, m.commands, m.searchResults.Playlists)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -243,7 +244,7 @@ func (m *mainModel) SelectItem() error {
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) { switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
case *spotify.FullArtistPage: case *spotify.FullArtistPage:
m.mode = SearchArtists m.mode = SearchArtists
new_items, err := SearchArtistsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullArtistPage)) new_items, err := SearchArtistsView(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullArtistPage))
if err != nil { if err != nil {
return err return err
} }
@ -251,7 +252,7 @@ func (m *mainModel) SelectItem() error {
m.list.ResetSelected() m.list.ResetSelected()
case *spotify.SimpleAlbumPage: case *spotify.SimpleAlbumPage:
m.mode = SearchAlbums m.mode = SearchAlbums
new_items, err := SearchAlbumsView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimpleAlbumPage)) new_items, err := SearchAlbumsView(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimpleAlbumPage))
if err != nil { if err != nil {
return err return err
} }
@ -260,7 +261,7 @@ func (m *mainModel) SelectItem() error {
case *spotify.SimplePlaylistPage: case *spotify.SimplePlaylistPage:
m.mode = SearchPlaylists m.mode = SearchPlaylists
playlists := m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimplePlaylistPage) playlists := m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.SimplePlaylistPage)
new_items, err := SearchPlaylistsView(m.ctx, m.client, playlists) new_items, err := SearchPlaylistsView(m.ctx, m.commands, playlists)
if err != nil { if err != nil {
return err return err
} }
@ -268,7 +269,7 @@ func (m *mainModel) SelectItem() error {
m.list.ResetSelected() m.list.ResetSelected()
case *spotify.FullTrackPage: case *spotify.FullTrackPage:
m.mode = SearchTracks m.mode = SearchTracks
new_items, err := SearchTracksView(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullTrackPage)) new_items, err := SearchTracksView(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(*spotify.FullTrackPage))
if err != nil { if err != nil {
return err return err
} }
@ -278,7 +279,7 @@ func (m *mainModel) SelectItem() error {
case SearchArtists: case SearchArtists:
m.mode = SearchArtist m.mode = SearchArtist
m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist) m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist)
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -287,7 +288,7 @@ func (m *mainModel) SelectItem() error {
case SearchArtist: case SearchArtist:
m.mode = SearchArtistAlbum m.mode = SearchArtistAlbum
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -296,7 +297,7 @@ func (m *mainModel) SelectItem() error {
case SearchAlbums: case SearchAlbums:
m.mode = SearchAlbum m.mode = SearchAlbum
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -306,7 +307,7 @@ func (m *mainModel) SelectItem() error {
m.mode = SearchPlaylist m.mode = SearchPlaylist
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist) playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
m.playlist = playlist m.playlist = playlist
new_items, err := PlaylistView(m.ctx, m.client, playlist) new_items, err := PlaylistView(m.ctx, m.commands, playlist)
if err != nil { if err != nil {
return err return err
} }
@ -316,7 +317,7 @@ func (m *mainModel) SelectItem() error {
switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) { switch m.list.SelectedItem().(mainItem).SpotifyItem.(type) {
case *spotify.FullArtistCursorPage: case *spotify.FullArtistCursorPage:
m.mode = Artists m.mode = Artists
new_items, err := ArtistsView(m.ctx, m.client) new_items, err := ArtistsView(m.ctx, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -324,7 +325,7 @@ func (m *mainModel) SelectItem() error {
m.list.ResetSelected() m.list.ResetSelected()
case *spotify.SavedAlbumPage: case *spotify.SavedAlbumPage:
m.mode = Albums m.mode = Albums
new_items, err := AlbumsView(m.ctx, m.client) new_items, err := AlbumsView(m.ctx, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -334,7 +335,7 @@ func (m *mainModel) SelectItem() error {
m.mode = Playlist m.mode = Playlist
playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist) playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist)
m.playlist = playlist m.playlist = playlist
new_items, err := PlaylistView(m.ctx, m.client, playlist) new_items, err := PlaylistView(m.ctx, m.commands, playlist)
if err != nil { if err != nil {
return err return err
} }
@ -342,7 +343,7 @@ func (m *mainModel) SelectItem() error {
m.list.ResetSelected() m.list.ResetSelected()
case *spotify.SavedTrackPage: case *spotify.SavedTrackPage:
m.mode = Tracks m.mode = Tracks
new_items, err := SavedTracksView(m.ctx, m.client) new_items, err := SavedTracksView(m.ctx, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -352,7 +353,7 @@ func (m *mainModel) SelectItem() error {
case Albums: case Albums:
m.mode = Album m.mode = Album
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -361,7 +362,7 @@ func (m *mainModel) SelectItem() error {
case Artist: case Artist:
m.mode = ArtistAlbum m.mode = ArtistAlbum
m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum)
new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.client) new_items, err := AlbumTracksView(m.ctx, m.album.ID, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -370,26 +371,26 @@ func (m *mainModel) SelectItem() error {
case Artists: case Artists:
m.mode = Artist m.mode = Artist
m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist) m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist)
new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.client) new_items, err := ArtistAlbumsView(m.ctx, m.artist.ID, m.commands)
if err != nil { if err != nil {
return err return err
} }
m.list.SetItems(new_items) m.list.SetItems(new_items)
m.list.ResetSelected() m.list.ResetSelected()
case Album, ArtistAlbum, SearchArtistAlbum, SearchAlbum: case Album, ArtistAlbum, SearchArtistAlbum, SearchAlbum:
go HandlePlayWithContext(m.ctx, m.client, &m.album.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.TotalPages)) go HandlePlayWithContext(m.ctx, m.commands, &m.album.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.TotalPages))
case Playlist, SearchPlaylist: case Playlist, SearchPlaylist:
go HandlePlayWithContext(m.ctx, m.client, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage)) go HandlePlayWithContext(m.ctx, m.commands, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
case Tracks: case Tracks:
go HandlePlayLikedSong(m.ctx, m.client, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage)) go HandlePlayLikedSong(m.ctx, m.commands, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
case SearchTracks: case SearchTracks:
go HandlePlayTrack(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.FullTrack).ID) go HandlePlayTrack(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.FullTrack).ID)
case Devices: case Devices:
go HandleSetDevice(m.ctx, m.client, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice)) go HandleSetDevice(m.ctx, m.commands, m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.PlayerDevice))
m.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue()) m.list.NewStatusMessage("Setting device to " + m.list.SelectedItem().FilterValue())
m.mode = "main" m.mode = "main"
m.list.NewStatusMessage("Setting view to main") m.list.NewStatusMessage("Setting view to main")
new_items, err := MainView(m.ctx, m.client) new_items, err := MainView(m.ctx, m.commands)
if err != nil { if err != nil {
return err return err
} }
@ -412,7 +413,7 @@ func Tick() tea.Cmd {
} }
func (m *mainModel) TickPlayback() { func (m *mainModel) TickPlayback() {
playing, _ := m.client.PlayerCurrentlyPlaying(m.ctx) playing, _ := m.commands.Client().PlayerCurrentlyPlaying(m.ctx)
if playing != nil && playing.Playing && playing.Item != nil { if playing != nil && playing.Playing && playing.Item != nil {
currentlyPlaying = playing currentlyPlaying = playing
playbackContext, _ = m.getContext(playing) playbackContext, _ = m.getContext(playing)
@ -423,7 +424,7 @@ func (m *mainModel) TickPlayback() {
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
playing, _ := m.client.PlayerCurrentlyPlaying(m.ctx) playing, _ := m.commands.Client().PlayerCurrentlyPlaying(m.ctx)
if playing != nil && playing.Playing && playing.Item != nil { if playing != nil && playing.Playing && playing.Item != nil {
currentlyPlaying = playing currentlyPlaying = playing
playbackContext, _ = m.getContext(playing) playbackContext, _ = m.getContext(playing)
@ -445,7 +446,7 @@ func (m mainModel) View() string {
func (m *mainModel) Typing(msg tea.KeyMsg) (bool, tea.Cmd) { func (m *mainModel) Typing(msg tea.KeyMsg) (bool, tea.Cmd) {
if msg.String() == "enter" { if msg.String() == "enter" {
items, result, err := SearchView(m.ctx, m.client, m.input.Value()) items, result, err := SearchView(m.ctx, m.commands, m.input.Value())
if err != nil { if err != nil {
return false, tea.Quit return false, tea.Quit
} }
@ -475,19 +476,19 @@ func (m *mainModel) getContext(playing *spotify.CurrentlyPlaying) (string, error
id := strings.Split(string(context.URI), ":")[2] id := strings.Split(string(context.URI), ":")[2]
switch context.Type { switch context.Type {
case "album": case "album":
album, err := m.client.GetAlbum(m.ctx, spotify.ID(id)) album, err := m.commands.Client().GetAlbum(m.ctx, spotify.ID(id))
if err != nil { if err != nil {
return "", err return "", err
} }
return album.Name, nil return album.Name, nil
case "playlist": case "playlist":
playlist, err := m.client.GetPlaylist(m.ctx, spotify.ID(id)) playlist, err := m.commands.Client().GetPlaylist(m.ctx, spotify.ID(id))
if err != nil { if err != nil {
return "", err return "", err
} }
return playlist.Name, nil return playlist.Name, nil
case "artist": case "artist":
artist, err := m.client.GetArtist(m.ctx, spotify.ID(id)) artist, err := m.commands.Client().GetArtist(m.ctx, spotify.ID(id))
if err != nil { if err != nil {
return "", err return "", err
} }
@ -547,16 +548,16 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
} }
if msg.String() == ">" { if msg.String() == ">" {
go HandleSeek(m.ctx, m.client, true) go HandleSeek(m.ctx, m.commands, true)
} }
if msg.String() == "<" { if msg.String() == "<" {
go HandleSeek(m.ctx, m.client, false) go HandleSeek(m.ctx, m.commands, false)
} }
if msg.String() == "+" { if msg.String() == "+" {
go HandleVolume(m.ctx, m.client, true) go HandleVolume(m.ctx, m.commands, true)
} }
if msg.String() == "-" { if msg.String() == "-" {
go HandleVolume(m.ctx, m.client, false) go HandleVolume(m.ctx, m.commands, false)
} }
// search input // search input
if m.input.Focused() { if m.input.Focused() {
@ -573,7 +574,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// enter device selection // enter device selection
if msg.String() == "d" { if msg.String() == "d" {
m.mode = Devices m.mode = Devices
new_items, err := DeviceView(m.ctx, m.client) new_items, err := DeviceView(m.ctx, m.commands)
if err != nil { if err != nil {
return m, tea.Quit return m, tea.Quit
} }
@ -624,24 +625,24 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd return m, cmd
} }
func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model, error) { func InitMain(ctx *gctx.Context, c *commands.Commands, mode Mode) (tea.Model, error) {
prog := progress.New(progress.WithColorProfile(2), progress.WithoutPercentage()) prog := progress.New(progress.WithColorProfile(2), progress.WithoutPercentage())
var err error var err error
lipgloss.SetColorProfile(2) lipgloss.SetColorProfile(2)
items := []list.Item{} items := []list.Item{}
switch mode { switch mode {
case Main: case Main:
items, err = MainView(ctx, client) items, err = MainView(ctx, c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
case Devices: case Devices:
items, err = DeviceView(ctx, client) items, err = DeviceView(ctx, c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
case Tracks: case Tracks:
items, err = SavedTracksView(ctx, client) items, err = SavedTracksView(ctx, c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -649,7 +650,7 @@ func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model,
m := mainModel{ m := mainModel{
list: list.New(items, list.NewDefaultDelegate(), 0, 0), list: list.New(items, list.NewDefaultDelegate(), 0, 0),
ctx: ctx, ctx: ctx,
client: client, commands: c,
mode: mode, mode: mode,
progress: prog, progress: prog,
} }

View File

@ -3,15 +3,15 @@ package tui
import ( import (
"fmt" "fmt"
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
"gitea.asdf.cafe/abs3nt/gospt/src/gctx" "gitea.asdf.cafe/abs3nt/gospt/src/gctx"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/zmb3/spotify/v2"
) )
// StartTea the entry point for the UI. Initializes the model. // StartTea the entry point for the UI. Initializes the model.
func StartTea(ctx *gctx.Context, client *spotify.Client, mode string) error { func StartTea(ctx *gctx.Context, cmd *commands.Commands, mode string) error {
m, err := InitMain(ctx, client, Mode(mode)) m, err := InitMain(ctx, cmd, Mode(mode))
if err != nil { if err != nil {
fmt.Println("UH OH") fmt.Println("UH OH")
} }

View File

@ -12,9 +12,9 @@ import (
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
) )
func DeviceView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { func DeviceView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
devices, err := client.PlayerDevices(ctx) devices, err := commands.Client().PlayerDevices(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -28,9 +28,9 @@ func DeviceView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
return items, nil return items, nil
} }
func PlaylistView(ctx *gctx.Context, client *spotify.Client, playlist spotify.SimplePlaylist) ([]list.Item, error) { func PlaylistView(ctx *gctx.Context, commands *commands.Commands, playlist spotify.SimplePlaylist) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
tracks, err := commands.PlaylistTracks(ctx, client, playlist.ID, 1) tracks, err := commands.PlaylistTracks(ctx, playlist.ID, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -47,9 +47,9 @@ func PlaylistView(ctx *gctx.Context, client *spotify.Client, playlist spotify.Si
return items, nil return items, nil
} }
func ArtistsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { func ArtistsView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
artists, err := commands.UserArtists(ctx, client, 1) artists, err := commands.UserArtists(ctx, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -64,7 +64,7 @@ func ArtistsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
return items, nil return items, nil
} }
func SearchArtistsView(ctx *gctx.Context, client *spotify.Client, artists *spotify.FullArtistPage) ([]list.Item, error) { func SearchArtistsView(ctx *gctx.Context, commands *commands.Commands, artists *spotify.FullArtistPage) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
for _, artist := range artists.Artists { for _, artist := range artists.Artists {
items = append(items, mainItem{ items = append(items, mainItem{
@ -77,10 +77,10 @@ func SearchArtistsView(ctx *gctx.Context, client *spotify.Client, artists *spoti
return items, nil return items, nil
} }
func SearchView(ctx *gctx.Context, client *spotify.Client, search string) ([]list.Item, *SearchResults, error) { func SearchView(ctx *gctx.Context, commands *commands.Commands, search string) ([]list.Item, *SearchResults, error) {
items := []list.Item{} items := []list.Item{}
result, err := commands.Search(ctx, client, search, 1) result, err := commands.Search(ctx, search, 1)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -114,9 +114,9 @@ func SearchView(ctx *gctx.Context, client *spotify.Client, search string) ([]lis
return items, results, nil return items, results, nil
} }
func AlbumsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { func AlbumsView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
albums, err := commands.UserAlbums(ctx, client, 1) albums, err := commands.UserAlbums(ctx, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -131,7 +131,7 @@ func AlbumsView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error)
return items, nil return items, nil
} }
func SearchPlaylistsView(ctx *gctx.Context, client *spotify.Client, playlists *spotify.SimplePlaylistPage) ([]list.Item, error) { func SearchPlaylistsView(ctx *gctx.Context, commands *commands.Commands, playlists *spotify.SimplePlaylistPage) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
for _, playlist := range playlists.Playlists { for _, playlist := range playlists.Playlists {
items = append(items, mainItem{ items = append(items, mainItem{
@ -143,7 +143,7 @@ func SearchPlaylistsView(ctx *gctx.Context, client *spotify.Client, playlists *s
return items, nil return items, nil
} }
func SearchAlbumsView(ctx *gctx.Context, client *spotify.Client, albums *spotify.SimpleAlbumPage) ([]list.Item, error) { func SearchAlbumsView(ctx *gctx.Context, commands *commands.Commands, albums *spotify.SimpleAlbumPage) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
for _, album := range albums.Albums { for _, album := range albums.Albums {
items = append(items, mainItem{ items = append(items, mainItem{
@ -156,9 +156,9 @@ func SearchAlbumsView(ctx *gctx.Context, client *spotify.Client, albums *spotify
return items, nil return items, nil
} }
func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, client *spotify.Client) ([]list.Item, error) { func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
albums, err := commands.ArtistAlbums(ctx, client, album, 1) albums, err := commands.ArtistAlbums(ctx, album, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -173,9 +173,9 @@ func ArtistAlbumsView(ctx *gctx.Context, album spotify.ID, client *spotify.Clien
return items, err return items, err
} }
func AlbumTracksView(ctx *gctx.Context, album spotify.ID, client *spotify.Client) ([]list.Item, error) { func AlbumTracksView(ctx *gctx.Context, album spotify.ID, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
tracks, err := commands.AlbumTracks(ctx, client, album, 1) tracks, err := commands.AlbumTracks(ctx, album, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -192,7 +192,7 @@ func AlbumTracksView(ctx *gctx.Context, album spotify.ID, client *spotify.Client
return items, err return items, err
} }
func SearchTracksView(ctx *gctx.Context, client *spotify.Client, tracks *spotify.FullTrackPage) ([]list.Item, error) { func SearchTracksView(ctx *gctx.Context, commands *commands.Commands, tracks *spotify.FullTrackPage) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
for _, track := range tracks.Tracks { for _, track := range tracks.Tracks {
items = append(items, mainItem{ items = append(items, mainItem{
@ -207,9 +207,9 @@ func SearchTracksView(ctx *gctx.Context, client *spotify.Client, tracks *spotify
return items, nil return items, nil
} }
func SavedTracksView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { func SavedTracksView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) {
items := []list.Item{} items := []list.Item{}
tracks, err := commands.TrackList(ctx, client, 1) tracks, err := commands.TrackList(ctx, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -226,7 +226,7 @@ func SavedTracksView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, er
return items, err return items, err
} }
func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) { func MainView(ctx *gctx.Context, commands *commands.Commands) ([]list.Item, error) {
var wg sync.WaitGroup var wg sync.WaitGroup
var saved_items *spotify.SavedTrackPage var saved_items *spotify.SavedTrackPage
var playlists *spotify.SimplePlaylistPage var playlists *spotify.SimplePlaylistPage
@ -237,7 +237,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
go func() { go func() {
defer wg.Done() defer wg.Done()
var err error var err error
saved_items, err = commands.TrackList(ctx, client, 1) saved_items, err = commands.TrackList(ctx, 1)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
@ -248,7 +248,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
go func() { go func() {
defer wg.Done() defer wg.Done()
var err error var err error
playlists, err = commands.Playlists(ctx, client, 1) playlists, err = commands.Playlists(ctx, 1)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
@ -259,7 +259,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
go func() { go func() {
defer wg.Done() defer wg.Done()
var err error var err error
artists, err = commands.UserArtists(ctx, client, 1) artists, err = commands.UserArtists(ctx, 1)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
@ -270,7 +270,7 @@ func MainView(ctx *gctx.Context, client *spotify.Client) ([]list.Item, error) {
go func() { go func() {
defer wg.Done() defer wg.Done()
var err error var err error
albums, err = commands.UserAlbums(ctx, client, 1) albums, err = commands.UserAlbums(ctx, 1)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return