diff --git a/helpers/mojolicious-radio-box.ini.sample b/helpers/mojolicious-radio-box.ini.sample new file mode 100644 index 0000000..d288c4c --- /dev/null +++ b/helpers/mojolicious-radio-box.ini.sample @@ -0,0 +1,12 @@ +# config for mojolicious-radio-box.pl server +# place this file into ~/.cmus/mojolicious-radio-box.ini + +# dir with m2u/pls playlist for internet radio +radio_playlist_dir = ~/Music/radio + +# host and port for http server +listen_address = http://*:8080 + +# settings for hypnotoad server +hypnotoad_workers = 3 +hypnotoad_accept_interval = 0.3 diff --git a/mojolicious-radio-box.pl b/mojolicious-radio-box.pl index 7c89c7c..52fca1b 100755 --- a/mojolicious-radio-box.pl +++ b/mojolicious-radio-box.pl @@ -25,6 +25,9 @@ =head1 Mojolicious radio box ini_file => "$ENV{HOME}/.cmus/mojolicious-radio-box.ini", last_track_file => "$ENV{HOME}/.cmus/last_track.json", playlist_file => "$ENV{HOME}/.cmus/playlist.pl", + listen_address => 'http://*:8080', + hypnotoad_workers => 2, + hypnotoad_accept_interval => 0.7, ); # ------------------------------------------------------------------------------ @@ -35,7 +38,7 @@ sub init { open my $FH, '<', $OPTIONS{ini_file} or die "Error open file: $!\n"; while (my $line = <$FH>) { chomp $line; - next if $line =~ m/^ \s* \# .* $/x; + next if $line =~ m/^ \s* $/x || $line =~ m/^ \s* \# .* $/x; my ($key, $value) = split /\s*=\s*/, $line, 2; $OPTIONS{$key} = $value; } @@ -397,13 +400,13 @@ sub _cmus_parse_info { app ->config( hypnotoad => { - listen => ['http://*:8080'], - workers => 2, - accept_interval => 0.7, + listen => [$OPTIONS{listen_address}], + workers => $OPTIONS{hypnotoad_workers}, + accept_interval => $OPTIONS{hypnotoad_accept_interval}, } ) ->secret('KxY0bCQwtVmQa2QdxqX8E0WtmVdpv362NJxofWP') - ->start('daemon', '--listen=http://*:8080', @ARGV); + ->start(@ARGV ? @ARGV : ("daemon", "--listen=$OPTIONS{listen_address}")); __DATA__ @@ index.html.ep diff --git a/src/mojolicious-lite-radio-box-server.pl b/src/mojolicious-lite-radio-box-server.pl index daed74a..02b97b1 100755 --- a/src/mojolicious-lite-radio-box-server.pl +++ b/src/mojolicious-lite-radio-box-server.pl @@ -25,6 +25,9 @@ =head1 Mojolicious radio box ini_file => "$ENV{HOME}/.cmus/mojolicious-radio-box.ini", last_track_file => "$ENV{HOME}/.cmus/last_track.json", playlist_file => "$ENV{HOME}/.cmus/playlist.pl", + listen_address => 'http://*:8080', + hypnotoad_workers => 2, + hypnotoad_accept_interval => 0.7, ); # ------------------------------------------------------------------------------ @@ -41,13 +44,13 @@ =head1 Mojolicious radio box app ->config( hypnotoad => { - listen => ['http://*:8080'], - workers => 2, - accept_interval => 0.7, + listen => [$OPTIONS{listen_address}], + workers => $OPTIONS{hypnotoad_workers}, + accept_interval => $OPTIONS{hypnotoad_accept_interval}, } ) ->secret('KxY0bCQwtVmQa2QdxqX8E0WtmVdpv362NJxofWP') - ->start('daemon', '--listen=http://*:8080', @ARGV); + ->start(@ARGV ? @ARGV : ("daemon", "--listen=$OPTIONS{listen_address}")); __DATA__ @@ index.html.ep diff --git a/src/util.pm b/src/util.pm index d8dbd7d..eaea363 100644 --- a/src/util.pm +++ b/src/util.pm @@ -5,7 +5,7 @@ sub init { open my $FH, '<', $OPTIONS{ini_file} or die "Error open file: $!\n"; while (my $line = <$FH>) { chomp $line; - next if $line =~ m/^ \s* \# .* $/x; + next if $line =~ m/^ \s* $/x || $line =~ m/^ \s* \# .* $/x; my ($key, $value) = split /\s*=\s*/, $line, 2; $OPTIONS{$key} = $value; }