Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: msoap/mojolicious-radio-box
base: 8440f3a0e1
...
head fork: msoap/mojolicious-radio-box
compare: 1d2636ee00
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
8 helpers/on_status_display.pl
View
@@ -11,14 +11,14 @@ =head1 DESCRIPTION
use strict;
use warnings;
-use JSON;
-
# ------------------------------------------------------------------------------
sub main {
my %params = @ARGV;
- open my $FH, '>', "$ENV{HOME}/.cmus/last_track.json" or die "Error open file: $!\n";
- print $FH to_json(\%params) . "\n";
+ open my $FH, '>', "$ENV{HOME}/.cmus/last_track.tsv" or die "Error open file: $!\n";
+ for my $key (keys %params) {
+ print $FH "$key\t$params{$key}\n";
+ }
close $FH;
}
28 mojolicious-radio-box.pl
View
@@ -23,7 +23,7 @@ =head1 Mojolicious radio box
our %OPTIONS = (
ini_file => "$ENV{HOME}/.cmus/mojolicious-radio-box.ini",
- last_track_file => "$ENV{HOME}/.cmus/last_track.json",
+ last_track_file => "$ENV{HOME}/.cmus/last_track.tsv",
playlist_file => "$ENV{HOME}/.cmus/playlist.pl",
listen_address => 'http://*:8080',
hypnotoad_workers => 5,
@@ -47,6 +47,9 @@ sub init {
}
$OPTIONS{is_mac} = 1 if $^O eq 'darwin';
+ $OPTIONS{is_linux} = 1 if $^O eq 'linux';
+ $OPTIONS{is_pulseaudio} = 1 if $OPTIONS{is_linux} && `pacmd --version` =~ m/^pacmd\s+\d+/;
+ $OPTIONS{is_alsa} = 1 if $OPTIONS{is_linux} && `amixer --version` =~ m/^amixer\s+version\s+\d+/;
}
# ------------------------------------------------------------------------------
@@ -127,14 +130,31 @@ sub cmus_get_info {
)
{
open my $FH, '<', $OPTIONS{last_track_file} or die "Error open file: $!\n";
- my $add_info = eval{from_json(join("", <$FH>))} || {};
+ my $add_info = {};
+ while (my $line = <$FH>) {
+ chomp $line;
+ my ($key, $value) = split "\t", $line, 2;
+ $add_info->{$key} = $value if length($key) > 0;
+ }
$info->{radio_title} = $add_info->{title} if $add_info->{title};
close $FH;
}
if ($OPTIONS{is_mac}) {
$info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
+ } elsif ($OPTIONS{is_pulseaudio}) {
+ my ($pa_info) = grep {/set-sink-volume/} `pacmd dump`;
+ $pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
+ if (defined $1 && hex($1) >= 0) {
+ $info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
+ }
+ } elsif ($OPTIONS{is_alsa}) {
+ my $alsa_info = join "#", grep {/Front\s+(Left|Right):\s+Playback/} `amixer get Master`;
+ if ($alsa_info =~ /\d+ \s+ \[(\d{1,3})%\] .+ \d+ \s+ \[(\d{1,3})%\]/sx) {
+ $info->{volume} = int((int($1) + int($2)) / 2);
+ }
}
+
$info->{server_version} = $VERSION;
return $info;
@@ -276,6 +296,10 @@ sub cmus_set_volume {
if ($OPTIONS{is_mac}) {
system("osascript", "-e", "set volume output volume $volume");
+ } elsif ($OPTIONS{is_pulseaudio}) {
+ system("pactl", "set-sink-volume", "0", "${volume}%");
+ } elsif ($OPTIONS{is_alsa}) {
+ system("amixer", "-q", "set", "Master", "${volume}%");
}
return;
23 src/cmus-client.pm
View
@@ -27,14 +27,31 @@ sub cmus_get_info {
)
{
open my $FH, '<', $OPTIONS{last_track_file} or die "Error open file: $!\n";
- my $add_info = eval{from_json(join("", <$FH>))} || {};
+ my $add_info = {};
+ while (my $line = <$FH>) {
+ chomp $line;
+ my ($key, $value) = split "\t", $line, 2;
+ $add_info->{$key} = $value if length($key) > 0;
+ }
$info->{radio_title} = $add_info->{title} if $add_info->{title};
close $FH;
}
if ($OPTIONS{is_mac}) {
$info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
+ } elsif ($OPTIONS{is_pulseaudio}) {
+ my ($pa_info) = grep {/set-sink-volume/} `pacmd dump`;
+ $pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
+ if (defined $1 && hex($1) >= 0) {
+ $info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
+ }
+ } elsif ($OPTIONS{is_alsa}) {
+ my $alsa_info = join "#", grep {/Front\s+(Left|Right):\s+Playback/} `amixer get Master`;
+ if ($alsa_info =~ /\d+ \s+ \[(\d{1,3})%\] .+ \d+ \s+ \[(\d{1,3})%\]/sx) {
+ $info->{volume} = int((int($1) + int($2)) / 2);
+ }
}
+
$info->{server_version} = $VERSION;
return $info;
@@ -176,6 +193,10 @@ sub cmus_set_volume {
if ($OPTIONS{is_mac}) {
system("osascript", "-e", "set volume output volume $volume");
+ } elsif ($OPTIONS{is_pulseaudio}) {
+ system("pactl", "set-sink-volume", "0", "${volume}%");
+ } elsif ($OPTIONS{is_alsa}) {
+ system("amixer", "-q", "set", "Master", "${volume}%");
}
return;
2  src/mojolicious-lite-radio-box-server.pl
View
@@ -23,7 +23,7 @@ =head1 Mojolicious radio box
our %OPTIONS = (
ini_file => "$ENV{HOME}/.cmus/mojolicious-radio-box.ini",
- last_track_file => "$ENV{HOME}/.cmus/last_track.json",
+ last_track_file => "$ENV{HOME}/.cmus/last_track.tsv",
playlist_file => "$ENV{HOME}/.cmus/playlist.pl",
listen_address => 'http://*:8080',
hypnotoad_workers => 5,
3  src/util.pm
View
@@ -14,6 +14,9 @@ sub init {
}
$OPTIONS{is_mac} = 1 if $^O eq 'darwin';
+ $OPTIONS{is_linux} = 1 if $^O eq 'linux';
+ $OPTIONS{is_pulseaudio} = 1 if $OPTIONS{is_linux} && `pacmd --version` =~ m/^pacmd\s+\d+/;
+ $OPTIONS{is_alsa} = 1 if $OPTIONS{is_linux} && `amixer --version` =~ m/^amixer\s+version\s+\d+/;
}
# ------------------------------------------------------------------------------

No commit comments for this range

Something went wrong with that request. Please try again.