Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
added support cmus-remote -Q "stream" field (cmus > 2.5.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
msoap committed Feb 15, 2013
1 parent b1142df commit df70812
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions mojolicious-radio-box.pl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ sub cmus_get_info {
my $info = _cmus_parse_info(`cmus-remote --query`);

# for internet-radio get title from file
if ($info->{status}
if (! exists $info->{stream}
&& $info->{status}
&& $info->{status} eq 'playing'
&& ($info->{duration} == -1 || $info->{file} =~ m[^https?://])
&& -r $OPTIONS{last_track_file}
Expand All @@ -135,7 +136,7 @@ sub cmus_get_info {
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};
$info->{stream} = $add_info->{title} if $add_info->{title};
close $FH;
}

Expand Down Expand Up @@ -591,8 +592,8 @@ sub _cmus_parse_info {
}
if (App.info.tag) {
position = parseInt(App.info.position) > 0 ? " (" + App.format_track_time(parseInt(App.info.position)) + ")" : "";
if (App.info.radio_title) {
$("#div_info").html("" + App.info.tag.title + "<br>\n<b>" + App.info.radio_title + position + "</b>");
if (App.info.stream) {
$("#div_info").html("" + App.info.tag.title + "<br>\n<b>" + App.info.stream + position + "</b>");
} else if (App.info.tag.artist && App.info.tag.album) {
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>");
Expand All @@ -601,7 +602,7 @@ sub _cmus_parse_info {
$("#div_info").html("<b>" + App.info.tag.title + position + "</b>");
}
}
if (App.info.radio_title || (App.info.file != null) && App.info.file.match(/https?:\/\//)) {
if (App.info.stream || (App.info.file != null) && App.info.file.match(/https?:\/\//)) {
$("#radio_stations").show();
if (App.radio_stations.length) {
App.render_select_radio();
Expand Down Expand Up @@ -649,7 +650,7 @@ sub _cmus_parse_info {
},
do_pause: function() {
$("#bt_pause").attr('disabled', 'disabled');
if (App.info.duration > 0 && !App.info.radio_title) {
if (App.info.duration > 0) {
return $.post('/pause', function(info_data) {
App.info = info_data.info;
return App.render_info();
Expand Down
5 changes: 3 additions & 2 deletions src/cmus-client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ sub cmus_get_info {
my $info = _cmus_parse_info(`cmus-remote --query`);

# for internet-radio get title from file
if ($info->{status}
if (! exists $info->{stream}
&& $info->{status}
&& $info->{status} eq 'playing'
&& ($info->{duration} == -1 || $info->{file} =~ m[^https?://])
&& -r $OPTIONS{last_track_file}
Expand All @@ -33,7 +34,7 @@ sub cmus_get_info {
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};
$info->{stream} = $add_info->{title} if $add_info->{title};
close $FH;
}

Expand Down
8 changes: 4 additions & 4 deletions src/radio-box-client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ window.App =
" (" + App.format_track_time(parseInt(App.info.position)) + ")"
else
""
if App.info.radio_title
if App.info.stream
$("#div_info").html """
#{App.info.tag.title}<br>
<b>#{App.info.radio_title}#{position}</b>
<b>#{App.info.stream}#{position}</b>
"""

else if App.info.tag.artist && App.info.tag.album
Expand All @@ -76,7 +76,7 @@ window.App =
<b>#{App.info.tag.title}#{position}</b>
"""

if App.info.radio_title || App.info.file? && App.info.file.match(/https?:\/\//)
if App.info.stream || App.info.file? && App.info.file.match(/https?:\/\//)
$("#radio_stations").show()
if App.radio_stations.length
App.render_select_radio()
Expand Down Expand Up @@ -112,7 +112,7 @@ window.App =
# events ....................................
do_pause: ->
$("#bt_pause").attr('disabled', 'disabled')
if App.info.duration > 0 && ! App.info.radio_title
if App.info.duration > 0
$.post '/pause', (info_data) ->
App.info = info_data.info
App.render_info()
Expand Down

0 comments on commit df70812

Please sign in to comment.