commit f23077ef880ceb803ec4bea44da76a687b6a7c5a
parent b7aa7e0ca27c5a7adbb72edb761880fa2afa61db
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Tue, 6 Oct 2020 11:18:59 +0200
Added installation info
Diffstat:
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,21 @@
+prefix=/usr/local
+datarootdir=$(prefix)/share
+etcdir=$(prefix)/etc/radio
+datadir=$(datarootdir)
+exec_prefix=$(prefix)
+bindir=$(exec_prefix)/bin
+mandir=$(datarootdir)/man
+man1dir=$(mandir)/man1
+
+all:
+ @echo "Targets: install, uninstall"
+
+install: radio
+ cp radio $(bindir)/
+ mkdir -p $(etcdir)
+ cp urls $(etcdir)/
+
+uninstall:
+ rm $(bindir)/radio
+ rm $(etcdir)/urls
+ rmdir $(etcdir)
diff --git a/README.md b/README.md
@@ -1,5 +1,11 @@
# radio: a command line radio player
Requires Ruby, and uses [mpv](https://mpv.io) as a backend.
-Radio channels are defined in \$HOME/.config/urls, see [urls](./urls) for an example.
+The default radio channels are defined in the file [`/usr/local/etc/radio/urls`](./urls).
+They can be overridden by defining channels in the file `$HOME/.config/radio/urls`.
The file uses the standard conf syntax.
+
+## Installation
+* Homebrew: `brew install thezeroalpha/formulae/conf`
+* Makefile: `make install`
+* Manual: download the `radio` script, make it executable, and put it in your `$PATH`
diff --git a/radio b/radio
@@ -47,6 +47,7 @@ class Subreddit
end
class Radio
+ DEFAULT_CONFIG_FILE = '/usr/local/etc/radio/urls'
CONFIG_FILE = "#{ENV['HOME']}/.config/radio/urls"
SUBREDDIT_CHANNEL = 'Play from music subreddit'
def initialize
@@ -54,13 +55,17 @@ class Radio
warn 'mpv not installed.'
exit 1
end
- unless File.exist? "#{ENV['HOME']}/.config/radio/urls"
+ if File.exist? CONFIG_FILE
+ cfg = CONFIG_FILE
+ elsif File.exist? DEFAULT_CONFIG_FILE
+ cfg = DEFAULT_CONFIG_FILE
+ else
warn "Please set URLs in #{ENV['HOME']}/.config/radio/urls."
exit 1
end
@channels = {}
- File.open(CONFIG_FILE, 'r').each do |line|
- unless line.match?(/^\s*\#/)
+ File.open(cfg, 'r').each do |line|
+ unless line.match?(/^\s*(\#|\s*$)/)
parts = line.chomp.split(/(?<=")\s+(?=http)/)
@channels[parts.first.gsub('"', '')] = parts.last
end