openSUSE Forums > Programming/Scripting » Shell script, Amarok currently playing.. need some help

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read

Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-Jul-2009, 10:21
Axeia's Avatar
Parent Penguin
 
Join Date: Jul 2008
Location: Netherlands
Posts: 967
Axeia is on a distinguished reputation roadAxeia is on a distinguished reputation road
Default Shell script, Amarok currently playing.. need some help

Okay this is what I got:
Code:
#! /bin/bash
BITRATE=$("qdbus org.kde.amarok /Player GetMetadata | grep bitrate | sed 's/audio-bitrate: //'")
ARTIST=$("qdbus org.kde.amarok /Player GetMetadata | grep artist | sed 's/artist: //'")
ALBUM=$("qdbus org.kde.amarok /Player GetMetadata | grep album | head -n 1 | sed 's/album: //'")
TITLE=$("qdbus org.kde.amarok /Player GetMetadata | grep title | tail -n 1 | sed 's/title: //'")
YEAR=$("qdbus org.kde.amarok /Player GetMetadata | grep year | sed 's/year: //'")
SAMPLERATE=$("qdbus org.kde.amarok /Player GetMetadata | grep audio-samplerate | sed 's/audio-samplerate: //'")

echo -e "np: $ARTIST - $TITLE <$ALBUM ($YEAR)> [$FILETYPE @ $BITRATE kbps | $SAMPLERATE hz ] [$NOW/$TIME]"
I think the intention should be clear, but in case it's not.
I want it to echo out the currently playing number with some more info
__________________
Special effects <- KDE 4.2 Showing off
More KDE -> PINK KDE
Reply With Quote
  #2 (permalink)  
Old 09-Jul-2009, 10:31
Flux Capacitor Penguin
 
Join Date: Jun 2008
Location: GMT+10
Posts: 5,109
ken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud of
Default Re: Shell script, Amarok currently playing.. need some help

Interesting, I had not seen qdbus in use before.

However on trying it here, I don't see Amarok on the dbus list. From some tutes, it appears that this requires Amarok 2. I'm still running Amarok 1.4. Do you have Amarok 2? What do you get when you just run

qdbus

? Is org.kde.amarok in the output? It isn't on mine.
Reply With Quote
  #3 (permalink)  
Old 09-Jul-2009, 10:34
microchip8's Avatar
Wise Penguin
 
Join Date: Jun 2008
Location: /dev/belgium
Posts: 1,971
microchip8 has a spectacular reputation aura aboutmicrochip8 has a spectacular reputation aura aboutmicrochip8 has a spectacular reputation aura aboutmicrochip8 has a spectacular reputation aura about
Default Re: Shell script, Amarok currently playing.. need some help

Code:
#! /bin/bash
BITRATE="$(qdbus org.kde.amarok /Player GetMetadata | grep bitrate | sed 's/audio-bitrate: //')"
ARTIST="$(qdbus org.kde.amarok /Player GetMetadata | grep artist | sed 's/artist: //')"
ALBUM="$(qdbus org.kde.amarok /Player GetMetadata | grep album | head -n 1 | sed 's/album: //')"
TITLE="$(qdbus org.kde.amarok /Player GetMetadata | grep title | tail -n 1 | sed 's/title: //')"
YEAR="$(qdbus org.kde.amarok /Player GetMetadata | grep year | sed 's/year: //')"
SAMPLERATE="$(qdbus org.kde.amarok /Player GetMetadata | grep audio-samplerate | sed 's/audio-samplerate: //')"

echo -e "np: $ARTIST - $TITLE <$ALBUM ($YEAR)> [$FILETYPE @ $BITRATE kbps | $SAMPLERATE hz ] [$NOW/$TIME]"
Works with Amarok2. You are placing the quotes incorrectly, see correction above
__________________
My site: http://microchip.bplaced.net
My repo: http://download.opensuse.org/repositories/home:/microchip8
SUSE Unbound Forum: http://suseunbound.lefora.com


Do coders dream of sheep() ?
Reply With Quote
  #4 (permalink)  
Old 09-Jul-2009, 10:41
Flux Capacitor Penguin
 
Join Date: Jun 2008
Location: GMT+10
Posts: 5,109
ken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud of
Default Re: Shell script, Amarok currently playing.. need some help

I would also add that you should avoid calling qdbus multiple times. It's easy enough to save the output in a shell variable and then grep that. Or pipe the output to a script which will do the parsing in one pass.
Reply With Quote
  #5 (permalink)  
Old 09-Jul-2009, 14:37
Axeia's Avatar
Parent Penguin
 
Join Date: Jul 2008
Location: Netherlands
Posts: 967
Axeia is on a distinguished reputation roadAxeia is on a distinguished reputation road
Default Re: Shell script, Amarok currently playing.. need some help

Thanks for the help, seems like I can't use it for what I had intended to.. kvirc.

Works fine from the shell though.
__________________
Special effects <- KDE 4.2 Showing off
More KDE -> PINK KDE
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2