Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Showing with 379 additions and 45 deletions.
  1. +196 −23 mojolicious-radio-box.pl
  2. +69 −10 src/cmus-client.pm
  3. +31 −8 src/index.html
  4. +1 −0 src/mojolicious-lite-radio-box-server.pl
  5. +66 −3 src/radio-box-client.coffee
  6. +13 −0 src/routers.pm
  7. +3 −1 src/util.pm
View
219 mojolicious-radio-box.pl
@@ -13,6 +13,7 @@
our %OPTIONS = (
ini_file => "$ENV{HOME}/.cmus/mojolicious-radio-box.ini",
last_track_file => "$ENV{HOME}/.cmus/last_track.txt",
+ playlist_file => "$ENV{HOME}/.cmus/playlist.pl",
);
# ------------------------------------------------------------------------------
@@ -30,11 +31,13 @@ sub init {
close $FH;
$OPTIONS{radio_playlist_dir} =~ s/^~/$ENV{HOME}/ if defined $OPTIONS{radio_playlist_dir};
}
+
+ $OPTIONS{is_mac} = 1 if $^O eq 'darwin';
}
# ------------------------------------------------------------------------------
-=head1 get_radio_stations
+=head2 get_radio_stations
Get array with radio-station urls (from $OPTIONS{radio_playlist_dir} dir)
@@ -89,7 +92,7 @@ =head1 cmus player client
# ------------------------------------------------------------------------------
-=head1 cmus_get_info
+=head2 cmus_get_info
Get info from cmus player
@@ -105,7 +108,7 @@ sub cmus_get_info {
# for internet-radio get title from file
if ($info->{status}
&& $info->{status} eq 'playing'
- && ($info->{duration} == -1 || $info->{file} =~ m[^http://])
+ && ($info->{duration} == -1 || $info->{file} =~ m[^https?://])
&& -r $OPTIONS{last_track_file}
)
{
@@ -115,12 +118,16 @@ sub cmus_get_info {
close $FH;
}
+ if ($OPTIONS{is_mac}) {
+ $info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
+ }
+
return $info;
}
# ------------------------------------------------------------------------------
-=head1 cmus_pause
+=head2 cmus_pause
Pause/unpause player
@@ -132,7 +139,7 @@ sub cmus_pause {
# ------------------------------------------------------------------------------
-=head1 cmus_play
+=head2 cmus_play
Play player
@@ -144,7 +151,7 @@ sub cmus_play {
# ------------------------------------------------------------------------------
-=head1 cmus_stop
+=head2 cmus_stop
Stop player
@@ -156,7 +163,7 @@ sub cmus_stop {
# ------------------------------------------------------------------------------
-=head1 cmus_next
+=head2 cmus_next
do next song
@@ -168,7 +175,7 @@ sub cmus_next {
# ------------------------------------------------------------------------------
-=head1 cmus_prev
+=head2 cmus_prev
do prev song
@@ -180,7 +187,7 @@ sub cmus_prev {
# ------------------------------------------------------------------------------
-=head1 cmus_play_radio
+=head2 cmus_play_radio
play radio by url
@@ -190,15 +197,46 @@ sub cmus_play_radio {
my $url = shift;
if ($url) {
- open my $FH, '|-', 'cmus-remote' or die "Error open file: $!\n";
- print $FH join("\n", 'view playlist'
+ open my $PIPE, '|-', 'cmus-remote' or die "Error open file: $!\n";
+ print $PIPE join("\n", 'view playlist'
+ , 'save'
, 'clear'
, 'player-stop'
, "add $url"
, 'player-play'
, 'player-next'
) . "\n";
+ close $PIPE;
+ }
+
+ return cmus_get_info();
+}
+
+# ------------------------------------------------------------------------------
+
+=head2 cmus_get_music
+
+=cut
+
+sub cmus_get_music {
+ if (-r $OPTIONS{playlist_file}) {
+ open my $FH, '<', $OPTIONS{playlist_file} or die "Error open file: $!\n";
+ my @playlist = grep {$_ && $_ ne '' && ! m|^https?://|}
+ map {chomp; $_}
+ <$FH>;
close $FH;
+
+ if (@playlist) {
+ open my $PIPE, '|-', 'cmus-remote' or die "Error open file: $!\n";
+ print $PIPE join("\n", 'view playlist'
+ , 'clear'
+ , 'player-stop'
+ , map({"add $_"} @playlist)
+ , 'player-play'
+ , 'player-next'
+ ) . "\n";
+ close $PIPE;
+ }
}
return cmus_get_info();
@@ -206,6 +244,30 @@ sub cmus_play_radio {
# ------------------------------------------------------------------------------
+=head2 cmus_set_volume
+
+Set sound volume
+
+=cut
+
+sub cmus_set_volume {
+ my $volume = shift;
+
+ die "cmus_set_volume: volume is invalid"
+ unless defined $volume
+ && $volume =~ /^\d+$/
+ && $volume >= 0
+ && $volume <= 100;
+
+ if ($OPTIONS{is_mac}) {
+ system("osascript", "-e", "set volume output volume $volume");
+ }
+
+ return;
+}
+
+# ------------------------------------------------------------------------------
+
=head1 _cmus_parse_info
Parse lines from cmus-remote -Q
@@ -276,6 +338,19 @@ sub _cmus_parse_info {
return $self->render_json({status => 'ok', info => cmus_play_radio($url)});
};
+any '/get_music' => sub {
+ my $self = shift;
+ return $self->render_json({status => 'ok', info => cmus_get_music()});
+};
+
+any '/set_volume' => sub {
+ my $self = shift;
+
+ my $volume = $self->param("volume");
+ cmus_set_volume($volume);
+ return $self->render_json({status => 'ok'});
+};
+
# go ---------------------------------------------------------------------------
init();
app
@@ -290,7 +365,7 @@ sub _cmus_parse_info {
<meta name="viewport" content="width=device-width, initial-scale=1.3, maximum-scale=2.0, user-scalable=yes"/>
<title>Mojolicious radio box</title>
<script src="/js/jquery.js"></script>
- <script src="script.js"></script>
+ <script src="/script.js"></script>
<style>
h1 {
font-size: 80%;
@@ -299,6 +374,7 @@ sub _cmus_parse_info {
width: 95px;
height: 30px;
top: 5px;
+ font-size: 10pt;
border: 1px solid #888;
border-radius: 5px;
background-color: #eee;
@@ -308,10 +384,11 @@ sub _cmus_parse_info {
box-shadow: 2px 2px 6px #519BB6;
}
button.nav_buttons i {
- font-size: 110%;
+ font-size: 95%;
}
#div_info {
- margin-top: 5px;
+ margin-top: 10px;
+ margin-bottom: 10px;
font-family: sans-serif;
font-size: 90%;
}
@@ -321,13 +398,26 @@ sub _cmus_parse_info {
font-family: sans-serif;
margin-top: 10px;
}
- #bt_get_radio {
+ #bt_get_radio, #bt_get_music {
width: 130px;
}
#radio_stations {
width: 170px;
display: none;
}
+ input#volume_slider {
+ margin: 7px 10px;
+ width: 150px;
+ }
+ .volume-buttons {
+ width: 50px;
+ position: relative;
+ top: -3px;
+ font-size: 10pt;
+ border: 1px solid #888;
+ border-radius: 5px;
+ background-color: #eee;
+ }
</style>
<link rel="stylesheet" href="/font-awesome.css">
</head>
@@ -335,12 +425,20 @@ sub _cmus_parse_info {
<h1>♫♬ Mojolicious radio box</h1>
<div>
<button class="nav_buttons" id="bt_prev"><i class="icon-backward"></i>&nbsp;&nbsp;prev</button>
- <button class="nav_buttons" id="bt_pause">pause</button>
+ <button class="nav_buttons" id="bt_pause"><i class="icon-play"></i>&nbsp;&nbsp;play</button>
<button class="nav_buttons" id="bt_next">next&nbsp;&nbsp;<i class="icon-forward"></i></button>
</div>
- <div id="div_info"></div><br>
- <button class="nav_buttons" id="bt_get_radio"><i class="icon-volume-up"></i>&nbsp;&nbsp;get radio&hellip;</button>
- <select id="radio_stations"></select>
+
+ <div id="div_info"></div>
+
+ <button class="nav_buttons" id="bt_get_radio"><i class="icon-tasks"></i>&nbsp;&nbsp;get radio&hellip;</button>
+ <select id="radio_stations"></select><br>
+ <button class="nav_buttons" id="bt_get_music"><i class="icon-music"></i>&nbsp;&nbsp;get music&hellip;</button><br><br>
+
+ <button id="volume_down" class="volume-buttons"><i class="icon-volume-down"></i></button>
+ <input id="volume_slider" type="range" min="0" max="100" step="1">
+ <button id="volume_up" class="volume-buttons"><i class="icon-volume-up" id="volume_up"></i></button>
+
<div id="div_error">Server unavailable&hellip;</div>
</body>
</html>
@@ -363,7 +461,20 @@ sub _cmus_parse_info {
$("#bt_next").on('click', App.do_next);
$("#bt_prev").on('click', App.do_prev);
$("#bt_get_radio").on('click', App.do_get_radio);
+ $("#bt_get_music").on('click', App.do_get_music);
$("#radio_stations").on('change', App.do_select_radio);
+ $("#volume_slider").on('change', {
+ absolute: true
+ }, App.do_change_volume);
+ $("#volume_slider").on('blur', {
+ absolute: true
+ }, App.do_change_volume);
+ $("#volume_down").on('click', {
+ down: 10
+ }, App.do_change_volume);
+ $("#volume_up").on('click', {
+ up: 10
+ }, App.do_change_volume);
$(document).ajaxError(function() {
return $("#div_error").show().fadeOut(1500, function() {
return $("button.nav_buttons").removeAttr('disabled');
@@ -381,6 +492,7 @@ sub _cmus_parse_info {
});
},
render_info: function() {
+ var duration, position;
$("button.nav_buttons").removeAttr('disabled');
if (App.info.status === 'playing') {
$("#bt_pause").html('<i class="icon-pause">&nbsp;&nbsp;pause');
@@ -393,9 +505,12 @@ sub _cmus_parse_info {
}
if (App.info.tag) {
if (App.info.radio_title) {
- $("#div_info").html("" + App.info.tag.title + "<br>\n<b>" + App.info.radio_title + "</b>");
+ position = parseInt(App.info.position) > 0 ? " (" + App.format_track_time(parseInt(App.info.position)) + ")" : "";
+ $("#div_info").html("" + App.info.tag.title + "<br>\n<b>" + App.info.radio_title + position + "</b>");
} else if (App.info.tag.artist && App.info.tag.album) {
- $("#div_info").html("" + App.info.tag.artist + "<br>\n<i>" + App.info.tag.album + "</i><br>\n<b>" + App.info.tag.title + "</b>");
+ duration = parseInt(App.info.duration) > 0 ? " (" + App.format_track_time(parseInt(App.info.duration)) + ")" : "";
+ $("#div_info").html("" + App.info.tag.artist + "<br>\n<i>" + App.info.tag.album + "</i><br>\n<b>" + App.info.tag.title + duration + "</b>");
+ $("#radio_stations").hide()[0].selectedIndex = 0;
} else {
$("#div_info").html("<b>" + App.info.tag.title + "</b>");
}
@@ -403,11 +518,14 @@ sub _cmus_parse_info {
if (App.info.radio_title && App.info.file.match(/http:\/\//)) {
$("#radio_stations").show();
if (App.radio_stations.length) {
- return App.render_select_radio();
+ App.render_select_radio();
} else {
- return App.do_get_radio();
+ App.do_get_radio();
}
}
+ if (App.info.volume !== void 0) {
+ return $('input#volume_slider').val(App.info.volume);
+ }
},
render_select_radio: function() {
var item, new_option, select_input, _i, _len, _ref, _results;
@@ -426,6 +544,23 @@ sub _cmus_parse_info {
}
return _results;
},
+ format_track_time: function(all_seconds) {
+ var hours, minutes, result, seconds;
+ hours = Math.floor(all_seconds / 3600);
+ minutes = Math.floor((all_seconds - hours * 3600) / 60);
+ seconds = (all_seconds - hours * 3600 - minutes * 60) % 60;
+ if (minutes < 10) {
+ minutes = "0" + minutes;
+ }
+ if (seconds < 10) {
+ seconds = "0" + seconds;
+ }
+ result = "" + minutes + ":" + seconds;
+ if (hours > 0) {
+ result = "" + hours + ":" + result;
+ }
+ return result;
+ },
do_pause: function() {
$("#bt_pause").attr('disabled', 'disabled');
if (App.info.duration > 0 && !App.info.radio_title) {
@@ -466,6 +601,12 @@ sub _cmus_parse_info {
return App.render_select_radio();
});
},
+ do_get_music: function() {
+ return $.get('/get_music', function(info_data) {
+ App.info = info_data.info;
+ return App.render_info();
+ });
+ },
do_select_radio: function(event) {
if (event.target.value) {
return $.get('/play_radio', {
@@ -475,6 +616,38 @@ sub _cmus_parse_info {
return App.render_info();
});
}
+ },
+ do_change_volume: function(event) {
+ var new_volume;
+ if (App._change_valume_tid) {
+ window.clearTimeout(App._change_valume_tid);
+ App._change_valume_tid = void 0;
+ }
+ new_volume = 0;
+ if (event.data.up) {
+ new_volume = App.info.volume + event.data.up;
+ if (new_volume > 100) {
+ new_volume = 100;
+ }
+ } else if (event.data.down) {
+ new_volume = App.info.volume - event.data.down;
+ if (new_volume < 0) {
+ new_volume = 0;
+ }
+ } else if (event.data.absolute) {
+ new_volume = parseInt($("#volume_slider").val());
+ } else {
+ return;
+ }
+ return App._change_valume_tid = window.setTimeout(function() {
+ if (new_volume !== void 0 && new_volume !== App.info.volume) {
+ App.info.volume = new_volume;
+ $("#volume_slider").val(new_volume);
+ return $.get('/set_volume', {
+ volume: new_volume
+ });
+ }
+ }, 200);
}
};
View
79 src/cmus-client.pm
@@ -6,7 +6,7 @@
# ------------------------------------------------------------------------------
-=head1 cmus_get_info
+=head2 cmus_get_info
Get info from cmus player
@@ -22,7 +22,7 @@ sub cmus_get_info {
# for internet-radio get title from file
if ($info->{status}
&& $info->{status} eq 'playing'
- && ($info->{duration} == -1 || $info->{file} =~ m[^http://])
+ && ($info->{duration} == -1 || $info->{file} =~ m[^https?://])
&& -r $OPTIONS{last_track_file}
)
{
@@ -32,12 +32,16 @@ sub cmus_get_info {
close $FH;
}
+ if ($OPTIONS{is_mac}) {
+ $info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
+ }
+
return $info;
}
# ------------------------------------------------------------------------------
-=head1 cmus_pause
+=head2 cmus_pause
Pause/unpause player
@@ -49,7 +53,7 @@ sub cmus_pause {
# ------------------------------------------------------------------------------
-=head1 cmus_play
+=head2 cmus_play
Play player
@@ -61,7 +65,7 @@ sub cmus_play {
# ------------------------------------------------------------------------------
-=head1 cmus_stop
+=head2 cmus_stop
Stop player
@@ -73,7 +77,7 @@ sub cmus_stop {
# ------------------------------------------------------------------------------
-=head1 cmus_next
+=head2 cmus_next
do next song
@@ -85,7 +89,7 @@ sub cmus_next {
# ------------------------------------------------------------------------------
-=head1 cmus_prev
+=head2 cmus_prev
do prev song
@@ -97,7 +101,7 @@ sub cmus_prev {
# ------------------------------------------------------------------------------
-=head1 cmus_play_radio
+=head2 cmus_play_radio
play radio by url
@@ -107,15 +111,46 @@ sub cmus_play_radio {
my $url = shift;
if ($url) {
- open my $FH, '|-', 'cmus-remote' or die "Error open file: $!\n";
- print $FH join("\n", 'view playlist'
+ open my $PIPE, '|-', 'cmus-remote' or die "Error open file: $!\n";
+ print $PIPE join("\n", 'view playlist'
+ , 'save'
, 'clear'
, 'player-stop'
, "add $url"
, 'player-play'
, 'player-next'
) . "\n";
+ close $PIPE;
+ }
+
+ return cmus_get_info();
+}
+
+# ------------------------------------------------------------------------------
+
+=head2 cmus_get_music
+
+=cut
+
+sub cmus_get_music {
+ if (-r $OPTIONS{playlist_file}) {
+ open my $FH, '<', $OPTIONS{playlist_file} or die "Error open file: $!\n";
+ my @playlist = grep {$_ && $_ ne '' && ! m|^https?://|}
+ map {chomp; $_}
+ <$FH>;
close $FH;
+
+ if (@playlist) {
+ open my $PIPE, '|-', 'cmus-remote' or die "Error open file: $!\n";
+ print $PIPE join("\n", 'view playlist'
+ , 'clear'
+ , 'player-stop'
+ , map({"add $_"} @playlist)
+ , 'player-play'
+ , 'player-next'
+ ) . "\n";
+ close $PIPE;
+ }
}
return cmus_get_info();
@@ -123,6 +158,30 @@ sub cmus_play_radio {
# ------------------------------------------------------------------------------
+=head2 cmus_set_volume
+
+Set sound volume
+
+=cut
+
+sub cmus_set_volume {
+ my $volume = shift;
+
+ die "cmus_set_volume: volume is invalid"
+ unless defined $volume
+ && $volume =~ /^\d+$/
+ && $volume >= 0
+ && $volume <= 100;
+
+ if ($OPTIONS{is_mac}) {
+ system("osascript", "-e", "set volume output volume $volume");
+ }
+
+ return;
+}
+
+# ------------------------------------------------------------------------------
+
=head1 _cmus_parse_info
Parse lines from cmus-remote -Q
View
39 src/index.html
@@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.3, maximum-scale=2.0, user-scalable=yes"/>
<title>Mojolicious radio box</title>
<script src="/js/jquery.js"></script>
- <script src="script.js"></script>
+ <script src="/script.js"></script>
<style>
h1 {
font-size: 80%;
@@ -13,6 +13,7 @@
width: 95px;
height: 30px;
top: 5px;
+ font-size: 10pt;
border: 1px solid #888;
border-radius: 5px;
background-color: #eee;
@@ -22,10 +23,11 @@
box-shadow: 2px 2px 6px #519BB6;
}
button.nav_buttons i {
- font-size: 110%;
+ font-size: 95%;
}
#div_info {
- margin-top: 5px;
+ margin-top: 10px;
+ margin-bottom: 10px;
font-family: sans-serif;
font-size: 90%;
}
@@ -35,13 +37,26 @@
font-family: sans-serif;
margin-top: 10px;
}
- #bt_get_radio {
+ #bt_get_radio, #bt_get_music {
width: 130px;
}
#radio_stations {
width: 170px;
display: none;
}
+ input#volume_slider {
+ margin: 7px 10px;
+ width: 150px;
+ }
+ .volume-buttons {
+ width: 50px;
+ position: relative;
+ top: -3px;
+ font-size: 10pt;
+ border: 1px solid #888;
+ border-radius: 5px;
+ background-color: #eee;
+ }
</style>
<link rel="stylesheet" href="/font-awesome.css">
</head>
@@ -49,12 +64,20 @@
<h1>♫♬ Mojolicious radio box</h1>
<div>
<button class="nav_buttons" id="bt_prev"><i class="icon-backward"></i>&nbsp;&nbsp;prev</button>
- <button class="nav_buttons" id="bt_pause">pause</button>
+ <button class="nav_buttons" id="bt_pause"><i class="icon-play"></i>&nbsp;&nbsp;play</button>
<button class="nav_buttons" id="bt_next">next&nbsp;&nbsp;<i class="icon-forward"></i></button>
</div>
- <div id="div_info"></div><br>
- <button class="nav_buttons" id="bt_get_radio"><i class="icon-volume-up"></i>&nbsp;&nbsp;get radio&hellip;</button>
- <select id="radio_stations"></select>
+
+ <div id="div_info"></div>
+
+ <button class="nav_buttons" id="bt_get_radio"><i class="icon-tasks"></i>&nbsp;&nbsp;get radio&hellip;</button>
+ <select id="radio_stations"></select><br>
+ <button class="nav_buttons" id="bt_get_music"><i class="icon-music"></i>&nbsp;&nbsp;get music&hellip;</button><br><br>
+
+ <button id="volume_down" class="volume-buttons"><i class="icon-volume-down"></i></button>
+ <input id="volume_slider" type="range" min="0" max="100" step="1">
+ <button id="volume_up" class="volume-buttons"><i class="icon-volume-up" id="volume_up"></i></button>
+
<div id="div_error">Server unavailable&hellip;</div>
</body>
</html>
View
1 src/mojolicious-lite-radio-box-server.pl
@@ -13,6 +13,7 @@
our %OPTIONS = (
ini_file => "$ENV{HOME}/.cmus/mojolicious-radio-box.ini",
last_track_file => "$ENV{HOME}/.cmus/last_track.txt",
+ playlist_file => "$ENV{HOME}/.cmus/playlist.pl",
);
# ------------------------------------------------------------------------------
View
69 src/radio-box-client.coffee
@@ -13,7 +13,12 @@ window.App =
$("#bt_next").on('click', App.do_next)
$("#bt_prev").on('click', App.do_prev)
$("#bt_get_radio").on('click', App.do_get_radio)
+ $("#bt_get_music").on('click', App.do_get_music)
$("#radio_stations").on('change', App.do_select_radio)
+ $("#volume_slider").on('change', {absolute: true}, App.do_change_volume)
+ $("#volume_slider").on('blur', {absolute: true}, App.do_change_volume)
+ $("#volume_down").on('click', {down: 10}, App.do_change_volume)
+ $("#volume_up").on('click', {up: 10}, App.do_change_volume)
$(document).ajaxError () ->
$("#div_error").show()
@@ -44,16 +49,27 @@ window.App =
if App.info.tag
if App.info.radio_title
+ position = if parseInt(App.info.position) > 0
+ " (" + App.format_track_time(parseInt(App.info.position)) + ")"
+ else
+ ""
$("#div_info").html """
#{App.info.tag.title}<br>
- <b>#{App.info.radio_title}</b>
+ <b>#{App.info.radio_title}#{position}</b>
"""
+
else if App.info.tag.artist && App.info.tag.album
+ duration = if parseInt(App.info.duration) > 0
+ " (" + App.format_track_time(parseInt(App.info.duration)) + ")"
+ else
+ ""
$("#div_info").html """
#{App.info.tag.artist}<br>
<i>#{App.info.tag.album}</i><br>
- <b>#{App.info.tag.title}</b>
+ <b>#{App.info.tag.title}#{duration}</b>
"""
+ $("#radio_stations").hide()[0].selectedIndex = 0
+
else
$("#div_info").html """
<b>#{App.info.tag.title}</b>
@@ -66,6 +82,9 @@ window.App =
else
App.do_get_radio()
+ if App.info.volume != undefined
+ $('input#volume_slider').val(App.info.volume)
+
# ...........................................
render_select_radio: ->
select_input = $('#radio_stations')[0]
@@ -77,8 +96,19 @@ window.App =
if App.info.radio_title && App.info.file.match(/http:\/\//) && App.info.file == item.url
new_option.selected = true
select_input.options.add(new_option)
-
+
# ...........................................
+ format_track_time: (all_seconds) ->
+ hours = Math.floor(all_seconds / 3600)
+ minutes = Math.floor((all_seconds - hours * 3600) / 60)
+ seconds = (all_seconds - hours * 3600 - minutes * 60) % 60
+ minutes = "0#{minutes}" if minutes < 10
+ seconds = "0#{seconds}" if seconds < 10
+ result = "#{minutes}:#{seconds}"
+ result = "#{hours}:#{result}" if hours > 0
+ return result
+
+ # events ....................................
do_pause: ->
$("#bt_pause").attr('disabled', 'disabled')
if App.info.duration > 0 && ! App.info.radio_title
@@ -116,6 +146,12 @@ window.App =
App.render_select_radio()
# ...........................................
+ do_get_music: ->
+ $.get '/get_music', (info_data) ->
+ App.info = info_data.info
+ App.render_info()
+
+ # ...........................................
do_select_radio: (event) ->
if event.target.value
$.get '/play_radio'
@@ -124,5 +160,32 @@ window.App =
App.info = info_data.info
App.render_info()
+ # ...........................................
+ do_change_volume: (event) ->
+ if App._change_valume_tid
+ window.clearTimeout App._change_valume_tid
+ App._change_valume_tid = undefined
+
+ new_volume = 0
+ if event.data.up
+ new_volume = App.info.volume + event.data.up
+ new_volume = 100 if new_volume > 100
+ else if event.data.down
+ new_volume = App.info.volume - event.data.down
+ new_volume = 0 if new_volume < 0
+ else if event.data.absolute
+ new_volume = parseInt($("#volume_slider").val())
+ else
+ return
+
+ App._change_valume_tid = window.setTimeout(
+ () ->
+ if new_volume != undefined && new_volume != App.info.volume
+ App.info.volume = new_volume
+ $("#volume_slider").val(new_volume)
+ $.get '/set_volume'
+ volume: new_volume
+ 200
+ )
# .............................................................................
$ () -> App.init()
View
13 src/routers.pm
@@ -40,3 +40,16 @@ any '/play_radio' => sub {
my $url = $self->param("url");
return $self->render_json({status => 'ok', info => cmus_play_radio($url)});
};
+
+any '/get_music' => sub {
+ my $self = shift;
+ return $self->render_json({status => 'ok', info => cmus_get_music()});
+};
+
+any '/set_volume' => sub {
+ my $self = shift;
+
+ my $volume = $self->param("volume");
+ cmus_set_volume($volume);
+ return $self->render_json({status => 'ok'});
+};
View
4 src/util.pm
@@ -12,11 +12,13 @@ sub init {
close $FH;
$OPTIONS{radio_playlist_dir} =~ s/^~/$ENV{HOME}/ if defined $OPTIONS{radio_playlist_dir};
}
+
+ $OPTIONS{is_mac} = 1 if $^O eq 'darwin';
}
# ------------------------------------------------------------------------------
-=head1 get_radio_stations
+=head2 get_radio_stations
Get array with radio-station urls (from $OPTIONS{radio_playlist_dir} dir)

No commit comments for this range

Something went wrong with that request. Please try again.