Compare commits

..

1 Commits

Author SHA1 Message Date
3b664e1996 no need to make the menu handle the player 2021-03-20 19:41:58 +00:00
14 changed files with 94 additions and 179 deletions

View File

@ -1,26 +0,0 @@
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
View File

@ -2,4 +2,3 @@
build/
vendor/
*.iml
go.sum

View File

@ -1,35 +0,0 @@
# 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.

View File

@ -140,7 +140,3 @@ To exit the program entirely, choose the __*Quit__ option, or just hit `[ENTER]`
* Change the precheck, to do ini file validation once, rather than every time a config value is called for.
* Add a way to capture favorite selections. Perhaps a preloaded search or something.
* Add color or a dashboard to the menu and player.
.

25
bitbucket-pipelines.yml Normal file
View File

@ -0,0 +1,25 @@
# Template Go (Golang) build
# This template allows you to validate your Go (Golang) code.
# The workflow allows running tests, build and code linting on the default branch.
image: golang:1.15
pipelines:
default:
- parallel:
- step:
name: Test and Build
script:
#- mkdir test-reports
#- go get -u github.com/jstemmer/go-junit-report
#- go test tests/* -v 2>&1 | go-junit-report > test-reports/report.xml
- mkdir build
- go mod vendor
- go mod tidy
- go build -o build/gostations github.com/gmgauthier/gostations
- step:
name: Lint code
image: golangci/golangci-lint:v1.31.0
script:
- golangci-lint run -v

View File

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"net"
@ -23,7 +22,7 @@ type stationRecord struct {
}
func RandomIP(iplist []net.IP) net.IP {
rand.NewSource(time.Now().Unix())
rand.Seed(time.Now().Unix())
randomIndex := rand.Intn(len(iplist))
return iplist[randomIndex]
}
@ -51,12 +50,7 @@ func GetStations(qstring string) ([]stationRecord, error) {
if err != nil {
log.Print(err.Error())
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Print(err.Error())
}
}(resp.Body)
defer resp.Body.Close()
var data []stationRecord
err = json.NewDecoder(resp.Body).Decode(&data)
@ -101,3 +95,5 @@ func StationSearch(name string, country string, state string, tags string, notok
prunedStations := pruneStations(stations) // eliminate stations that are reporting down.
return prunedStations, err
}

View File

@ -1,21 +0,0 @@
$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

View File

@ -1,23 +1,16 @@
#!/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)
CANONICAL_VERSION=$(cat ./VERSION)
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
go build -o build/gostations -ldflags "-X main.version=$VERSION_STRING"

View File

@ -1,20 +0,0 @@
#!/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

View File

@ -4,35 +4,25 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
)
func isInstalled(name string) bool {
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)
}
cmd := exec.Command("/bin/sh", "-c", "command -v " + name)
if err := cmd.Run(); err != nil {
return false
}
return true
}
func subExecute(program string, args ...string) ([]byte, error) {
func subExecute(program string, args ...string) {
cmd := exec.Command(program, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stderr = os.Stdout
err := cmd.Run()
if err != nil {
fmt.Printf("%v\n", err)
}
return cmd.CombinedOutput()
outp, _ := cmd.CombinedOutput()
fmt.Println(outp)
}

View File

@ -4,7 +4,6 @@ import (
"errors"
"log"
"os"
"runtime"
"strconv"
"github.com/alyu/configparser"
@ -22,18 +21,9 @@ func str2int(strnum string) int {
func configStat(configFile string) string{
xdgConfigPath := os.Getenv("XDG_CONFIG_HOME")
if xdgConfigPath == "" {
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
}
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.")

29
go.sum Normal file
View File

@ -0,0 +1,29 @@
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 h1:7xqw01UYS+KCI25bMrPxwNYkSns2Db1ziQPpVq99FpE=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 h1:f5gsjBiF9tRRVomCvrkGMMWI8W1f2OBFar2c5oakAP0=
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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
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=

View File

@ -29,8 +29,7 @@ func RadioMenu(stations []stationRecord) *wmenu.Menu {
if opts[0].Text == "Quit"{Quit()}
val := fmt.Sprintf("%s",opts[0].Value)
fmt.Printf("Streaming: " + opts[0].Text + "\n")
stdout, _ := subExecute(player(), options(), val)
fmt.Println(stdout)
subExecute(player(), options(), val)
err := menu.Run()
if err != nil {
log.Fatal("Oops! " + err.Error())