Discussion:
Execute External Commands
Storm Dragon
2011-04-25 00:16:48 UTC
Permalink
Hi,
I read a while back about a patch that adds the ability to run external
commands. I was wondering if this makes it possible to call external
services like lastfmsubmit when a song starts playing? In order for this
to work it would have to be able to pass information about the currently
playing track like title, artist, etc to the external command. Is this
possible yet, and if so, can someone please send me an example of
syntax?
thanks
Storm
--
Vinux Publicity Coordinator: http://www.vinuxproject.org/
Registered Linux user number 508465: http://counter.li.org/
My blog, Thoughts of a Dragon: http://www.stormdragon.us/
How many Internet mail list subscribers does it take to change a lightbulb? http://goo.gl/eO4PJ
Get yourself a Frostbox http://www.frostbitesystems.com/
It's always darkest just before the lights go out.
-- Alex Clark
$ fortune
Jason Woofenden
2011-04-25 00:24:58 UTC
Permalink
Post by Storm Dragon
Hi,
I read a while back about a patch that adds the ability to run external
commands. I was wondering if this makes it possible to call external
services like lastfmsubmit when a song starts playing? In order for this
to work it would have to be able to pass information about the currently
playing track like title, artist, etc to the external command. Is this
possible yet, and if so, can someone please send me an example of
syntax?
I haven't played with the new shell command, but you'll probably
want to use the status_display_program feature for scrobbling,
which calls a program/script of your choice automatically when the
play state changes (eg when a new song starts). There are some
existing scrobbling solutions on this page of our wiki:

http://cmus.sourceforge.net/wiki/doku.php?id=status_display_programs

Take care, - Jason
Storm Dragon
2011-04-25 00:41:25 UTC
Permalink
Hi,
Is there a way to do it so that it only happens on some songs, maybe
create a key binding? I don't want to scrobble everything.
Thanks
Storm
--
Vinux Publicity Coordinator: http://www.vinuxproject.org/
Registered Linux user number 508465: http://counter.li.org/
My blog, Thoughts of a Dragon: http://www.stormdragon.us/
How many Internet mail list subscribers does it take to change a lightbulb? http://goo.gl/eO4PJ
My last.fm profile: http://www.last.fm/user/stormdragon2976
"Have you ever been alone at night, thought you heard footsteps behind, and turned around and no one's there? And as you quicken up your pace you'll find it hard to look again because you're sure that someone's there."
Iron Maiden
Post by Jason Woofenden
Post by Storm Dragon
Hi,
I read a while back about a patch that adds the ability to run external
commands. I was wondering if this makes it possible to call external
services like lastfmsubmit when a song starts playing? In order for this
to work it would have to be able to pass information about the currently
playing track like title, artist, etc to the external command. Is this
possible yet, and if so, can someone please send me an example of
syntax?
I haven't played with the new shell command, but you'll probably
want to use the status_display_program feature for scrobbling,
which calls a program/script of your choice automatically when the
play state changes (eg when a new song starts). There are some
http://cmus.sourceforge.net/wiki/doku.php?id=status_display_programs
Take care, - Jason
Johannes Weißl
2011-04-25 00:46:40 UTC
Permalink
Hello Storm,
Post by Storm Dragon
Is there a way to do it so that it only happens on some songs, maybe
create a key binding? I don't want to scrobble everything.
Yes, you have to create a wrapper script (explained in the wiki). I have
something like this in my status_display_program.sh:

function check () {
while [ $# -gt 0 ] ; do
case "$1" in
artist)
shift
[ "$1" = "Unwanted artist" ] && exit 0
shift
;;
*)
shift
;;
esac
done
}

check "$@"
cmuscrobbler "$@" &



Johannes
Storm Dragon
2011-06-15 23:51:12 UTC
Permalink
Hi,
I am revisiting this topic after a couple of months because I can't
figure out how to do something that is probably actually pretty easy. I
use the Twitter program TTYtter:
http://www.floodgap.com/software/ttytter
and would like to bind a key to post the currently playing song to
Twitter using it. I read the example for bindable scripts on:
http://cmus.sourceforge.net/wiki/doku.php?id=shell_scripts
but it didn't seem to be what I need. Basically, when I press shift+T
for example, it should run the command:
ttytter -status="#nowplaying $title by $artest from $album."
I usually add the last.fm link for the search of the song, but I think
if someone gets me started with the script I should be able to add that
part.
Also, because not all of my music has information incoded, it would be
cool to be able to use the song name minus the extension if the artist,
title, and album information are blank.
Thanks for any help
Storm
--
Vinux Publicity Coordinator: http://www.vinuxproject.org/
Registered Linux user number 508465: http://counter.li.org/
My blog, Thoughts of a Dragon: http://www.stormdragon.us/
How many Internet mail list subscribers does it take to change a lightbulb? http://goo.gl/eO4PJ
Get paid to read email: http://is.gd/feRiB
"Somehow I'm still here to explain that the darkest hour never comes in the night."
Shinedown
Post by Johannes Weißl
Hello Storm,
Post by Storm Dragon
Is there a way to do it so that it only happens on some songs, maybe
create a key binding? I don't want to scrobble everything.
Yes, you have to create a wrapper script (explained in the wiki). I have
function check () {
while [ $# -gt 0 ] ; do
case "$1" in
artist)
shift
[ "$1" = "Unwanted artist" ] && exit 0
shift
;;
*)
shift
;;
esac
done
}
Johannes
------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
Johannes Weißl
2011-06-16 00:51:45 UTC
Permalink
Hi,
Post by Storm Dragon
I am revisiting this topic after a couple of months because I can't
figure out how to do something that is probably actually pretty easy. I
http://www.floodgap.com/software/ttytter
and would like to bind a key to post the currently playing song to
http://cmus.sourceforge.net/wiki/doku.php?id=shell_scripts
but it didn't seem to be what I need. Basically, when I press shift+T
ttytter -status="#nowplaying $title by $artest from $album."
Ok, no problem :-)! I created an example program here:
http://cmus.sourceforge.net/wiki/doku.php?id=cmus_ttytter

Is it working for you?
Post by Storm Dragon
I usually add the last.fm link for the search of the song, but I think
if someone gets me started with the script I should be able to add that
part.
Yes, should be just something like:

lastfm_link=$(python -c "from urllib import quote_plus
print 'http://www.last.fm/music/'+quote_plus('$artist')+'/_/'+quote_plus('$title')")
Post by Storm Dragon
Also, because not all of my music has information incoded, it would be
cool to be able to use the song name minus the extension if the artist,
title, and album information are blank.
Already included!

Greetings,
Johannes
Storm Dragon
2011-06-16 02:18:55 UTC
Permalink
Hi,
Awesome! Thanks, it works great. :)
Storm
--
Vinux Publicity Coordinator: http://www.vinuxproject.org/
Registered Linux user number 508465: http://counter.li.org/
My blog, Thoughts of a Dragon: http://www.stormdragon.us/
How many Internet mail list subscribers does it take to change a lightbulb? http://goo.gl/eO4PJ
Get paid to read email: http://is.gd/feRiB
"It's not our aim to hum, to aspirate, to perish tardily. It's our goal to be, and to become, and to rise constantly."
Van Canto
Post by Johannes Weißl
Hi,
Post by Storm Dragon
I am revisiting this topic after a couple of months because I can't
figure out how to do something that is probably actually pretty easy. I
http://www.floodgap.com/software/ttytter
and would like to bind a key to post the currently playing song to
http://cmus.sourceforge.net/wiki/doku.php?id=shell_scripts
but it didn't seem to be what I need. Basically, when I press shift+T
ttytter -status="#nowplaying $title by $artest from $album."
http://cmus.sourceforge.net/wiki/doku.php?id=cmus_ttytter
Is it working for you?
Post by Storm Dragon
I usually add the last.fm link for the search of the song, but I think
if someone gets me started with the script I should be able to add that
part.
lastfm_link=$(python -c "from urllib import quote_plus
print 'http://www.last.fm/music/'+quote_plus('$artist')+'/_/'+quote_plus('$title')")
Post by Storm Dragon
Also, because not all of my music has information incoded, it would be
cool to be able to use the song name minus the extension if the artist,
title, and album information are blank.
Already included!
Greetings,
Johannes
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
gt
2011-06-16 08:30:47 UTC
Permalink
Post by Storm Dragon
Hi,
Awesome! Thanks, it works great. :)
Storm
Hello Storm Dragon.

Sorry for the offtopic post, but I would suggest you read these:

http://www.idallen.com/topposting.html

http://mailformat.dan.info/quoting/bottom-posting.html

Please, use bottom or interleaved posting, as it'll be easier for others
to understand the context of your mail.

Thanks

Storm Dragon
2011-06-16 04:21:46 UTC
Permalink
Hi,
I have modified the script somewhat to add the last.fm url, shortened
with is.gd, and to also turn album, artist, and/or title in to hashtags
if they are one word. So, for example, DragonForce becomes #DragonForce.
I have pasted it below in case you would like to add it to the wiki. I
read a suggestion to use --data-urlencode with curl to make sure
everything was encoded correctly but couldn't get it to work.
I am also having a slight problem, it seems like I had it once before,
but I can't remember how to fix it. I have softvolume set to true. Even
at 100% it is still very quiet. Is there a way to raise the volume even
more?
Here's the script:
#!/bin/bash

if ! cmus-remote -C >/dev/null 2>&1 ; then
echo >&2 "cmus is not running"
exit 1
fi

info=$(cmus-remote -Q)

state=$(echo "$info" | sed -n 's/^status //p')
if [ "$state" = "stopped" ] ; then
echo >&2 "no song playing currently, aborting!"
exit 1
fi


file=$(echo "$info" | sed -n 's/^file //p')
artist=$(echo "$info" | sed -n 's/^tag artist //p')
if [[ $(echo "$artist" | sed 's/ /./g') == "$artist" && -n
"$artist" ]] ; then
artist="#$artist"
fi
album=$(echo "$info" | sed -n 's/^tag album //p')
if [[ $(echo "$album" | sed 's/ /./g') == "$album" && -n
"$album" ]] ; then
album="#$album"
fi
title=$(echo "$info" | sed -n 's/^tag title //p')
if [[ $(echo "$title" | sed 's/ /./g') == "$title" && -n
"$title" ]] ; then
title="#$title"
fi
if [ -z "$title" ] ; then
title=$(basename "$file" | sed 's/\.[A-Za-z0-9]*$//')
fi

if [ -n "$title" -a -n "$artist" -a -n "$album" ] ; then
msg="$title by $artist from $album"
longUrl="http://www.last.fm/search?q=${artist}%2B${title}"
else
msg="$title"
longUrl="http://www.last.fm/search?q=$(echo "$title" | tr -d "-"
| tr -s " " | sed 's/ /%2B/g')"
fi

shortUrl=$(curl http://is.gd/api.php?longurl=$longUrl)
if [[ ${#msg[*]} -lt "121" ]] ; then
msg="$msg $shortUrl"
fi
ttytter -norc -silent -readline=0 -status="#nowplaying $msg."
exit 0

Thanks
Storm
--
Vinux Publicity Coordinator: http://www.vinuxproject.org/
Registered Linux user number 508465: http://counter.li.org/
My blog, Thoughts of a Dragon: http://www.stormdragon.us/
How many Internet mail list subscribers does it take to change a lightbulb? http://goo.gl/eO4PJ
Get yourself a Frostbox http://www.frostbitesystems.com/
"It's not our aim to hum, to aspirate, to perish tardily. It's our goal to be, and to become, and to rise constantly."
Van Canto
Post by Johannes Weißl
Hi,
Post by Storm Dragon
I am revisiting this topic after a couple of months because I can't
figure out how to do something that is probably actually pretty easy. I
http://www.floodgap.com/software/ttytter
and would like to bind a key to post the currently playing song to
http://cmus.sourceforge.net/wiki/doku.php?id=shell_scripts
but it didn't seem to be what I need. Basically, when I press shift+T
ttytter -status="#nowplaying $title by $artest from $album."
http://cmus.sourceforge.net/wiki/doku.php?id=cmus_ttytter
Is it working for you?
Post by Storm Dragon
I usually add the last.fm link for the search of the song, but I think
if someone gets me started with the script I should be able to add that
part.
lastfm_link=$(python -c "from urllib import quote_plus
print 'http://www.last.fm/music/'+quote_plus('$artist')+'/_/'+quote_plus('$title')")
Post by Storm Dragon
Also, because not all of my music has information incoded, it would be
cool to be able to use the song name minus the extension if the artist,
title, and album information are blank.
Already included!
Greetings,
Johannes
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
Johannes Weißl
2011-06-16 05:55:40 UTC
Permalink
Hi,
Post by Storm Dragon
I have pasted it below in case you would like to add it to the wiki. I
read a suggestion to use --data-urlencode with curl to make sure
everything was encoded correctly but couldn't get it to work.
Thanks! I uploaded a modified version to the wiki page (with working
curl urlencode and last.fm xml characters fix). Also I think the length
check (121) was buggy.
Post by Storm Dragon
I am also having a slight problem, it seems like I had it once before,
but I can't remember how to fix it. I have softvolume set to true. Even
at 100% it is still very quiet. Is there a way to raise the volume even
more?
Hmm, this was one thing I also noticed when I worked on the softvol
code. The alsa softvol module e.g. can increase the volume, but this is
theoretically limited (you can't increase the volume of the samples
arbitrarily since they will clip). So making much effort for e.g.
110% is not worth it in my opinion. Can't you change the master volume
or the volume of cmus in case of PulseAudio?


Johannes
Storm Dragon
2011-06-16 06:31:47 UTC
Permalink
Hi,
Cool, the volume issue is fixed. As soon as I read the solution about
turning it up with Pulse I remembered doing it last time.
That revamp of the Tweet code is awesome. I don't know why I didn't
think of just using wc like that, and I learned some more about curl.
One thing I didn't understand in the function though:
if [ -n "$value" -a "$value" = "$(echo "$value" | tr -d
"[:space:]")" ] ; then
the second part only has 1 =, so I thought it should be a variable
assignment. I always thought it had to be == when comparing strings. It
still works though. Can you tell me what's happening there?
Thanks
Storm
--
Vinux Publicity Coordinator: http://www.vinuxproject.org/
Registered Linux user number 508465: http://counter.li.org/
My blog, Thoughts of a Dragon: http://www.stormdragon.us/
How many Internet mail list subscribers does it take to change a lightbulb? http://goo.gl/eO4PJ
Vinux is Linux done right: http://www.vinuxproject.org/
"One more time we stare into the blackened sky, for tonight, in our hearts now we feel. One last time see our destiny reveal."
DragonForce
Post by Johannes Weißl
Hi,
Post by Storm Dragon
I have pasted it below in case you would like to add it to the wiki. I
read a suggestion to use --data-urlencode with curl to make sure
everything was encoded correctly but couldn't get it to work.
Thanks! I uploaded a modified version to the wiki page (with working
curl urlencode and last.fm xml characters fix). Also I think the length
check (121) was buggy.
Post by Storm Dragon
I am also having a slight problem, it seems like I had it once before,
but I can't remember how to fix it. I have softvolume set to true. Even
at 100% it is still very quiet. Is there a way to raise the volume even
more?
Hmm, this was one thing I also noticed when I worked on the softvol
code. The alsa softvol module e.g. can increase the volume, but this is
theoretically limited (you can't increase the volume of the samples
arbitrarily since they will clip). So making much effort for e.g.
110% is not worth it in my opinion. Can't you change the master volume
or the volume of cmus in case of PulseAudio?
Johannes
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
Jason Woofenden
2011-06-16 06:43:50 UTC
Permalink
Post by Storm Dragon
if [ -n "$value" -a "$value" = "$(echo "$value" | tr -d
"[:space:]")" ] ; then
the second part only has 1 =, so I thought it should be a variable
assignment. I always thought it had to be == when comparing strings. It
still works though. Can you tell me what's happening there?
Lots of languages use == for comparison... but not bash. Bash (and
most shells) do this for assignment:

foo="bar"

And do this for testing:

if [ "$foo" = "bar" ]

which is a shorthand for:

if test "$foo" = "bar"

so "=" is not syntax, but is being passed to the "test" command,
where it's interpreted as the equality operator. The "test" command
does not have access to the variables (just the values passed to
it) so it cannot change them. See also:

man test


Take care, - Jason
Loading...