Skip to content

Commit

Permalink
Downloadable stations file
Browse files Browse the repository at this point in the history
Updated instructions
  • Loading branch information
entonio committed Jun 3, 2024
1 parent c3fde03 commit cf69a85
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Clicking the server name will run a shell command to restart the server. This ma

Clicking the song name will save it to an SQLite database file if specified in the configuration. A value `$HOME` in the path will be replaced by the user's home directory.

The configuration Stations field can be used to specify a link to download the radio stations file from. If it doesn't work for some reason, the local file is used.

The word _taboleta_ vaguely refers to the informal config file format used, and it's written precisely as intended.

Settings.taboleta
Expand Down Expand Up @@ -49,6 +51,9 @@ SQLite $HOME/Musicas.sqlite
# stop mpd, the OS service manager should respawn it
Restart killall -9 mpd
# link to download the stations list from
Stations https://some.link/to/your/playlist
```

Building
Expand Down
57 changes: 54 additions & 3 deletions source/app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
"hash/fnv"
"io"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -35,6 +37,7 @@ type Settings struct {
Language string
SQLite string
Restart []string
Stations string
Predefined Radio
}

Expand Down Expand Up @@ -62,7 +65,7 @@ func Start() {
CONFIG_DIR = findConfigDir()
SETTINGS = readSettings(CONFIG_DIR)
log.Printf("SETTINGS: %+v\n", SETTINGS)
radios := readRadios(CONFIG_DIR)
radios, _ := readRadios(CONFIG_DIR, SETTINGS.Stations)
log.Printf("RADIOS: %+v\n", radios)
TRANSLATOR = translate.NewTranslator(filepath.Join(CONFIG_DIR, "translations.csv"), "pt")

Expand Down Expand Up @@ -198,15 +201,39 @@ func readSettings(configDir string) (settings Settings) {
settings.SQLite = value
case "Restart":
settings.Restart = strings.Split(value, " ")
case "Stations":
settings.Stations = value
default:
log.Printf("Unexpected key: [%s]", key)
}
}
return
}

func readRadios(configDir string) (radios []Radio) {
text, err := taboleta.TextAtPath(filepath.Join(configDir, "Radios.taboleta"))
func hash(s string) string {
f := fnv.New128a()
f.Write([]byte(s))
var b []byte
f.Sum(b)
return string(b)
}

func readRadios(configDir string, link string) (radios []Radio, err error) {
if len(link) > 0 {
path := filepath.Join(configDir, "Radios."+hash(SETTINGS.Radio)+".taboleta")
httpGet(link, path)
radios, err = readRadiosFile(path)
if err == nil {
return
}
os.Exit(1)
}

return readRadiosFile(filepath.Join(configDir, "Radios.taboleta"))
}

func readRadiosFile(path string) (radios []Radio, err error) {
text, err := taboleta.TextAtPath(path)
if err != nil {
log.Println(err)
return
Expand All @@ -233,6 +260,30 @@ func readRadios(configDir string) (radios []Radio) {
return
}

func httpGet(from string, to string) (err error) {
response, err := http.Get(from)
if err != nil {
log.Println(err)
return
}
defer response.Body.Close()

f, err := os.Create(to)
if err != nil {
log.Println(err)
return
}
defer f.Close()

_, err = io.Copy(f, response.Body)
if err != nil {
log.Println(err)
return
}

return
}

func t(key string) string {
return TRANSLATOR.Translate(SETTINGS.Language, key)
}
Expand Down
1 change: 1 addition & 0 deletions source/config/mac/Settings.taboleta
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Trim \[onAir:.+\]
Language pt
SQLite $HOME/Dropbox/Musicas.sqlite
Restart killall -9 mpd
Stations https://tulimonstro.net/radio/default
Binary file modified source/packaging/mac/Resources/installer-mac.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/resources/installer-mac.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cf69a85

Please sign in to comment.