Compare commits
41 Commits
v0.1-alpha
...
master
Author | SHA1 | Date | |
---|---|---|---|
505e25189e | |||
2b1c44a619 | |||
be1a214a13 | |||
c34bdf66f2 | |||
1f27512017 | |||
3ae9f2afa2 | |||
767b1e8a7c | |||
cda405a9e2 | |||
5fa2bc67fd | |||
d92771b7ec | |||
a2c48e95b7 | |||
8c0e3a896d | |||
|
ea29c29531 | ||
|
fd70f428ae | ||
c2508127b4 | |||
|
d0a8fdfb11 | ||
|
8a78251c05 | ||
|
00c8b76fe0 | ||
|
27a7d9f60b | ||
|
027d922916 | ||
|
758d317d0f | ||
|
44080ebac9 | ||
|
0fa518cd00 | ||
|
b2a096a956 | ||
|
419372c49d | ||
eb19d5280a | |||
1cbf1c542e | |||
702edbc7a4 | |||
8df21e59b0 | |||
|
370876db38 | ||
|
be14b434fc | ||
|
39d1baf41b | ||
|
e67d973c2f | ||
|
9dd8ef46bd | ||
|
b6b35d1000 | ||
|
967337a938 | ||
|
ca2978318b | ||
|
d2c1b6af28 | ||
|
b6e5c15d1c | ||
|
9bd0bbda1c | ||
d68490ee57 |
26
.gitea/workflows/build.yml
Normal file
26
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,26 @@
|
||||
name: gobuild
|
||||
|
||||
on: [push]
|
||||
|
||||
env:
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: golang-latest
|
||||
|
||||
steps:
|
||||
- name: Lets See What We Have
|
||||
run:
|
||||
uname -a
|
||||
&& echo $PATH
|
||||
&& echo $GOPATH
|
||||
&& which go
|
||||
&& go version
|
||||
- name: Clone Repo
|
||||
run:
|
||||
git clone https://repos.gmgauthier.com/gmgauthier/gostations.git .
|
||||
&& ls -la
|
||||
- name: Linux Build
|
||||
run:
|
||||
./ci-build.sh
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
build/
|
||||
vendor/
|
||||
*.iml
|
||||
go.sum
|
||||
|
35
README-CONFIGS.md
Normal file
35
README-CONFIGS.md
Normal file
@ -0,0 +1,35 @@
|
||||
# FOR WINDOWS USERS
|
||||
|
||||
|
||||
|
||||
## MPV
|
||||
MPV insists on opening a GUI (or "pseudo-gui" as they call it) window, whether you like it or not.
|
||||
So, here is the best mpv.conf I could come up with, under those
|
||||
circumstances:
|
||||
```ini
|
||||
[default]
|
||||
terminal=yes
|
||||
audio-display=no
|
||||
video=no
|
||||
force-window=no
|
||||
window-minimized=yes
|
||||
idle=yes
|
||||
```
|
||||
The window will still be created, but at least, it will be minimized to the taskbar.
|
||||
|
||||
You should put this file in: `%USERPROFILE%\AppData\Roaming\mpv.net\mpv.conf`
|
||||
|
||||
## RADIOSTATIONS.INI
|
||||
Make sure your `gostations.exe` is somewhere in your searchable %PATH%. Then, you should
|
||||
only need to change the player.command option:
|
||||
```ini
|
||||
[DEFAULT]
|
||||
radio_browser.api=all.api.radio-browser.info
|
||||
player.command=mpvnet.exe
|
||||
player.options=--no-video
|
||||
menu_items.max=9999
|
||||
```
|
||||
|
||||
# FOR EVERYONE ELSE
|
||||
|
||||
Continue as you are. The sane people don't need to do anything different.
|
@ -138,4 +138,9 @@ To exit the program entirely, choose the __*Quit__ option, or just hit `[ENTER]`
|
||||
### TODO
|
||||
|
||||
* Change the precheck, to do ini file validation once, rather than every time a config value is called for.
|
||||
* Add color or a dashboard to the menu and player.
|
||||
* Add a way to capture favorite selections. Perhaps a preloaded search or something.
|
||||
* Add color or a dashboard to the menu and player.
|
||||
|
||||
|
||||
.
|
||||
|
||||
|
42
browser.go
42
browser.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
@ -12,17 +13,17 @@ import (
|
||||
)
|
||||
|
||||
type stationRecord struct {
|
||||
Name string `json:"name"`
|
||||
Codec string `json:"codec"`
|
||||
Name string `json:"name"`
|
||||
Codec string `json:"codec"`
|
||||
Bitrate json.Number `json:"bitrate"`
|
||||
Countrycode string `json:"countrycode"`
|
||||
Tags string `json:"tags"`
|
||||
Url string `json:"url"`
|
||||
Lastcheck int `json:"lastcheckok"`
|
||||
Countrycode string `json:"countrycode"`
|
||||
Tags string `json:"tags"`
|
||||
Url string `json:"url"`
|
||||
Lastcheck int `json:"lastcheckok"`
|
||||
}
|
||||
|
||||
func RandomIP(iplist []net.IP) net.IP {
|
||||
rand.Seed(time.Now().Unix())
|
||||
rand.NewSource(time.Now().Unix())
|
||||
randomIndex := rand.Intn(len(iplist))
|
||||
return iplist[randomIndex]
|
||||
}
|
||||
@ -44,13 +45,18 @@ func GetApiHost() string {
|
||||
return apiHost
|
||||
}
|
||||
|
||||
func GetStations(qstring string) ([]stationRecord, error){
|
||||
urlstr := fmt.Sprintf("https://%s/json/stations/search?%s&limit=%d",GetApiHost(),qstring,maxitems())
|
||||
func GetStations(qstring string) ([]stationRecord, error) {
|
||||
urlstr := fmt.Sprintf("https://%s/json/stations/search?%s&limit=%d", GetApiHost(), qstring, maxitems())
|
||||
resp, err := http.Get(urlstr)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
log.Print(err.Error())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
}
|
||||
}(resp.Body)
|
||||
|
||||
var data []stationRecord
|
||||
err = json.NewDecoder(resp.Body).Decode(&data)
|
||||
@ -72,28 +78,26 @@ func pruneStations(stations []stationRecord) []stationRecord {
|
||||
|
||||
func StationSearch(name string, country string, state string, tags string, notok bool) ([]stationRecord, error) {
|
||||
params := url.Values{}
|
||||
if name != ""{
|
||||
if name != "" {
|
||||
params.Add("name", name)
|
||||
}
|
||||
if country != "" {
|
||||
params.Add("country", country)
|
||||
}
|
||||
if state != ""{
|
||||
if state != "" {
|
||||
params.Add("state", state)
|
||||
}
|
||||
if tags != ""{
|
||||
params.Add("tag",tags)
|
||||
if tags != "" {
|
||||
params.Add("tag", tags)
|
||||
}
|
||||
|
||||
stations, err := GetStations(params.Encode())
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if notok{
|
||||
if notok {
|
||||
return stations, err
|
||||
} // otherwise prune the list
|
||||
prunedStations := pruneStations(stations) // eliminate stations that are reporting down.
|
||||
return prunedStations, err
|
||||
}
|
||||
|
||||
|
||||
|
3
browser_test.go
Normal file
3
browser_test.go
Normal file
@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
|
21
build.ps1
Normal file
21
build.ps1
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
$current_directory = "$(pwd.exe)"
|
||||
Set-Variable -Name GOPATH -Value "$HOME/go:$current_directory"
|
||||
|
||||
# NOTE: The following commands assumes you have Git For Windows
|
||||
# installed, which comes with a bunch of GNU tools packaged for windows:
|
||||
Set-Variable -Name GIT_COMMIT -Value "$(git rev-list -1 HEAD)"
|
||||
Set-Variable -Name CANONICAL_VERSION -Value "$(cat.exe ./VERSION)-$(uname)"
|
||||
Set-Variable -Name VERSION_STRING -Value "$CANONICAL_VERSION-$GIT_COMMIT"
|
||||
|
||||
Set-Variable -Name buildpath -Value "build/$(uname)/gostations.exe"
|
||||
|
||||
go mod vendor
|
||||
go mod tidy
|
||||
|
||||
go build -o "$buildpath" -ldflags "-X main.version=$VERSION_STRING"
|
||||
|
||||
& $buildpath -v
|
||||
|
||||
Copy-Item $buildpath $HOME/.local/bin -Force
|
||||
|
23
build.sh
Executable file
23
build.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
GOPATH=$HOME/go
|
||||
GOPATH=$GOPATH:$(pwd)
|
||||
export GOPATH
|
||||
|
||||
GIT_COMMIT=$(git rev-list -1 HEAD)
|
||||
export GIT_COMMIT
|
||||
CANONICAL_VERSION=$(cat ./VERSION)-$(uname)
|
||||
export CANONICAL_VERSION
|
||||
VERSION_STRING="$CANONICAL_VERSION-$GIT_COMMIT"
|
||||
export VERSION_STRING
|
||||
|
||||
buildpath="build/$(uname)/gostations"
|
||||
|
||||
go mod vendor
|
||||
go mod tidy
|
||||
|
||||
go build -o "$buildpath" -ldflags "-X main.version=$VERSION_STRING"
|
||||
|
||||
"$buildpath" -v
|
||||
|
||||
cp "$buildpath" ~/.local/bin
|
20
ci-build.sh
Executable file
20
ci-build.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
mkdir build
|
||||
|
||||
GIT_COMMIT=$(git rev-list -1 HEAD)
|
||||
export GIT_COMMIT
|
||||
CANONICAL_VERSION=$(cat ./VERSION)-$(uname)
|
||||
export CANONICAL_VERSION
|
||||
VERSION_STRING="$CANONICAL_VERSION-$GIT_COMMIT"
|
||||
export VERSION_STRING
|
||||
|
||||
buildpath="build/$(uname)/gostations"
|
||||
|
||||
/usr/local/go/bin/go mod vendor
|
||||
/usr/local/go/bin/go mod tidy
|
||||
|
||||
/usr/local/go/bin/go build -o "$buildpath" -ldflags "-X main.version=$VERSION_STRING"
|
||||
|
||||
"$buildpath" -v
|
||||
|
13
commander.go
13
commander.go
@ -4,10 +4,21 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func isInstalled(name string) bool {
|
||||
cmd := exec.Command("/bin/sh", "-c", "command -v " + name)
|
||||
var cmd *exec.Cmd
|
||||
|
||||
// check for the operating system
|
||||
if runtime.GOOS == "windows" {
|
||||
// 'where' command is used on Windows to locate executables
|
||||
cmd = exec.Command("where.exe", name)
|
||||
} else {
|
||||
// 'command' is used on Unix systems
|
||||
cmd = exec.Command("/bin/sh", "-c", "command -v "+name)
|
||||
}
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return false
|
||||
}
|
||||
|
31
config.go
31
config.go
@ -2,36 +2,47 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/alyu/configparser"
|
||||
)
|
||||
|
||||
// str2int
|
||||
func str2int(strnum string) int {
|
||||
i, err := strconv.Atoi(strnum)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(2)
|
||||
return 9999
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func configStat(configFile string) string{
|
||||
func configStat(configFile string) string {
|
||||
xdgConfigPath := os.Getenv("XDG_CONFIG_HOME")
|
||||
if xdgConfigPath == "" {
|
||||
xdgConfigPath = os.Getenv("HOME")+"/.config"
|
||||
if runtime.GOOS == "windows" {
|
||||
xdgConfigPath = os.Getenv("USERPROFILE") + "\\.config"
|
||||
} else {
|
||||
xdgConfigPath = os.Getenv("HOME") + "/.config"
|
||||
}
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
configFile = xdgConfigPath + "\\gostations\\" + configFile
|
||||
} else {
|
||||
configFile = xdgConfigPath + "/gostations/" + configFile
|
||||
}
|
||||
configFile = xdgConfigPath + "/gostations/" + configFile
|
||||
|
||||
if _, err := os.Stat(configFile); errors.Is(err, os.ErrNotExist) {
|
||||
log.Printf("Your stations config file seems to be missing. A default will be generated.")
|
||||
err = createIniFile(configFile)
|
||||
if err != nil {
|
||||
log.Printf("Erorr creating ini file...")
|
||||
log.Fatal(err.Error())
|
||||
errs := createIniFile(configFile)
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
log.Printf("Erorr: %s", err.Error())
|
||||
log.Fatal("Cannot continue.")
|
||||
}
|
||||
}
|
||||
}
|
||||
return configFile
|
||||
|
60
config_test.go
Normal file
60
config_test.go
Normal file
@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
//str2int
|
||||
func Test_str2int(t *testing.T){
|
||||
t.Run("Testing normal integer:", teststr2intFunc("5", 5))
|
||||
t.Run("Testing large integer:", teststr2intFunc("4294967296",4294967296))
|
||||
t.Run("Testing negative integer:", teststr2intFunc("-5", -5))
|
||||
t.Run("Testing invalid input:", teststr2intFunc("a", 9999))
|
||||
}
|
||||
|
||||
func teststr2intFunc(numstr string, expected int) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
if !assert.Equal(t, expected, str2int(numstr)) {
|
||||
t.Error(fmt.Sprintf("%d does not equal %d", str2int(numstr), expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_api(t *testing.T) {
|
||||
expectedApi := "all.api.radio-browser.info"
|
||||
api := api()
|
||||
pass := assert.Equal(t, expectedApi, api)
|
||||
if !pass {
|
||||
t.Error(fmt.Sprintf("`%s does not match %s", api, expectedApi))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_player(t *testing.T) {
|
||||
expectedPlayer := "mpv"
|
||||
player := player()
|
||||
pass := assert.Equal(t, expectedPlayer, player)
|
||||
if !pass {
|
||||
t.Error(fmt.Sprintf("`%s does not match %s", player, expectedPlayer))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_options(t *testing.T) {
|
||||
expectedOptions := "--no-video"
|
||||
options := options()
|
||||
pass := assert.Equal(t, expectedOptions, options)
|
||||
if !pass {
|
||||
t.Error(fmt.Sprintf("`%s does not match %s", options, expectedOptions))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_maxitems(t *testing.T) {
|
||||
expectedMaxItems := 9999
|
||||
maxItems := maxitems()
|
||||
pass := assert.Equal(t, expectedMaxItems, maxItems)
|
||||
if !pass {
|
||||
t.Error(fmt.Sprintf("`%d does not match %d", maxItems, expectedMaxItems))
|
||||
}
|
||||
}
|
43
filer.go
43
filer.go
@ -6,32 +6,41 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func createDir(fpath string) error {
|
||||
if err := os.Mkdir(filepath.Dir(fpath + string(filepath.Separator)), 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createIniFile(fpath string) error {
|
||||
func createIniFile(fpath string) []error {
|
||||
log.Printf("Creating config file: %s\n", fpath)
|
||||
var errorlist []error
|
||||
if err := os.MkdirAll(filepath.Dir(fpath), 0770); err != nil {
|
||||
return err
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
|
||||
file, err := os.Create(fpath)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return err
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
|
||||
_, err = file.Write([]byte("[DEFAULT]\n"))
|
||||
_, err = file.Write([]byte("radio_browser.api=all.api.radio-browser.info\n"))
|
||||
_, err = file.Write([]byte("player.command=mpv\n"))
|
||||
_, err = file.Write([]byte("player.options=--no-video\n"))
|
||||
_, err = file.Write([]byte("menu_items.max=9999\n"))
|
||||
if _, err := file.Write([]byte("[DEFAULT]\n")); err != nil {
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
if _, err := file.Write([]byte("radio_browser.api=all.api.radio-browser.info\n")); err != nil {
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
if _, err := file.Write([]byte("player.command=mpv\n")); err != nil {
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
if _, err := file.Write([]byte("player.options=--no-video\n")); err != nil {
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
if _, err := file.Write([]byte("menu_items.max=9999\n")); err != nil {
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
errorlist = append(errorlist, err)
|
||||
}
|
||||
}()
|
||||
|
||||
return err
|
||||
return errorlist
|
||||
}
|
||||
|
1
go.mod
1
go.mod
@ -5,4 +5,5 @@ go 1.16
|
||||
require (
|
||||
github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc
|
||||
github.com/dixonwille/wmenu/v5 v5.1.0
|
||||
github.com/stretchr/testify v1.4.0
|
||||
)
|
||||
|
26
go.sum
26
go.sum
@ -1,26 +0,0 @@
|
||||
github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc h1:eN2FUvn4J1A31pICABioDYukoh1Tmlei6L3ImZUin/I=
|
||||
github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc/go.mod h1:BYq/NZTroWuzkvsTPJgRBqSHGxKMHCz06gtlfY/W5RU=
|
||||
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/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 h1:d/cVoZOrJPJHKH1NdeUjyVAWKp4OpOT+Q+6T1sH7jeU=
|
||||
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
|
||||
github.com/dixonwille/wlog/v3 v3.0.1 h1:ViTSsNNndHlKW5S89x5O0KSTpTT9zdPqrkA/TZYY8+s=
|
||||
github.com/dixonwille/wlog/v3 v3.0.1/go.mod h1:fPYZR9Ne5gFh3N8b3CuXVWHWxkY6Yg1wCeS3Km6Nc0I=
|
||||
github.com/dixonwille/wmenu/v5 v5.1.0 h1:sKBHDoQ945NRvK0Eitd0kHDYHl1IYOSr1sdCK9c+Qr0=
|
||||
github.com/dixonwille/wmenu/v5 v5.1.0/go.mod h1:l6EGfXHaN6DPgv5+V5RY+cydAXJsj/oDZVczcdukPzc=
|
||||
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
|
||||
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8=
|
||||
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e h1:KhcknUwkWHKZPbFy2P7jH5LKJ3La+0ZeknkkmrSgqb0=
|
||||
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
|
||||
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/dixonwille/wmenu/v5"
|
||||
@ -30,7 +31,10 @@ func RadioMenu(stations []stationRecord) *wmenu.Menu {
|
||||
fmt.Printf("Streaming: " + opts[0].Text + "\n")
|
||||
stdout, _ := subExecute(player(), options(), val)
|
||||
fmt.Println(stdout)
|
||||
menu.Run()
|
||||
err := menu.Run()
|
||||
if err != nil {
|
||||
log.Fatal("Oops! " + err.Error())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
for _, station := range stations {
|
||||
|
32
stations.go
32
stations.go
@ -6,27 +6,34 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func precheck(){
|
||||
if !isInstalled(player()){
|
||||
var version string
|
||||
|
||||
func showVersion() {
|
||||
fmt.Println(version)
|
||||
}
|
||||
|
||||
func precheck() {
|
||||
if !isInstalled(player()) {
|
||||
fmt.Printf("%s is either not installed, or not on your $PATH. Cannot continue.\n", player())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main(){
|
||||
func main() {
|
||||
argCount := len(os.Args[1:])
|
||||
|
||||
var (
|
||||
name string
|
||||
name string
|
||||
country string
|
||||
state string
|
||||
tags string
|
||||
state string
|
||||
tags string
|
||||
notok bool
|
||||
version bool
|
||||
)
|
||||
flag.Usage = func() {
|
||||
fmt.Printf("Usage: \n")
|
||||
fmt.Printf(" gostations ")
|
||||
fmt.Printf(" [-n \"name\"] [-c \"home country\"] [-s \"home state\"] [-t \"ordered,tag,list\"] [-x]\n")
|
||||
fmt.Printf(" [-n \"name\"] [-c \"home country\"] [-s \"home state\"] [-t \"ordered,tag,list\"] [-x] [-v]\n")
|
||||
flag.PrintDefaults()
|
||||
fmt.Printf(" -h (or none)\n")
|
||||
fmt.Printf("\tThis help message\n")
|
||||
@ -35,13 +42,20 @@ func main(){
|
||||
flag.StringVar(&country, "c", "", "Home country.")
|
||||
flag.StringVar(&state, "s", "", "Home state (if in the United States).")
|
||||
flag.StringVar(&tags, "t", "", "Tag (or comma-separated tag list)")
|
||||
flag.BoolVar(¬ok, "x", false,"If toggled, will show stations that are down")
|
||||
flag.BoolVar(¬ok, "x", false, "If toggled, will show stations that are down")
|
||||
flag.BoolVar(&version, "v", false, "Show version.")
|
||||
flag.Parse()
|
||||
|
||||
if argCount == 0 {
|
||||
flag.Usage()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if version {
|
||||
showVersion()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
precheck()
|
||||
|
||||
stations, _ := StationSearch(name, country, state, tags, notok)
|
||||
@ -52,4 +66,4 @@ func main(){
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user