You are not logged in.
Pages: 1
Hi!
I'm trying to display the data of the actual song in amarok2 in conky.
I don't have any problem getting the common information by the command qdbus, but I still want to know the total time of the song and the reproduced portion.
Here my script:
#!/bin/bash
# amaroK info display script by eirc <eirc.eirc@gmail.com>
#
# requirements: amaroK (!)
# for Collection stats to work amarok must be using
# mySQL to store it's collection
case "$1" in
# Now Playing Info
artist)
str=`qdbus org.kde.amarok /Player GetMetadata | grep artist`
#if (( $str )); then
echo ${str:0:40}
#else
# str=`dcop amarok player path | gawk 'BEGIN {FS="/"} {print $(NF-1);}'`
# echo ${str:0:40}
#fi
;;
title)
str=`qdbus org.kde.amarok /Player GetMetadata | grep title`
#if (( $str )); then
echo ${str:0:40}
#else
# str=`dcop amarok player path | gawk 'BEGIN {FS="/"} {print $NF;}'`
# echo ${str:0:40}
#fi
;;
album) qdbus org.kde.amarok /Player GetMetadata | grep album ;;
year) qdbus org.kde.amarok /Player GetMetadata | grep year ;;
genre) qdbus org.kde.amarok /Player GetMetadata | grep genre ;;
progress)
curr=`dcop amarok player trackCurrentTime` #<----- To be fixed
tot=`dcop amarok player trackTotalTime` #<----- To be fixed
if (( $tot )); then
expr $curr \* 100 / $tot
fi
;;
currenttime)
tmp=`dcop amarok player trackCurrentTime` #<----- To be fixed
min=`expr $tmp / 60`
sec=`expr $tmp % 60`
c=`expr $sec \< 10`
if (($c)); then
echo $min:0$sec
else
echo $min:$sec
fi
;;
totaltime)
tmp=`dcop amarok player trackTotalTime` #<----- To be fixed
min=`expr $tmp / 60`
sec=`expr $tmp % 60`
c=`expr $sec \< 10`
if (($c)); then
echo $min:0$sec
else
echo $min:$sec
fi
;;
# Collection Info
#totalArtists) dcop amarok collection totalArtists ;;
#totalAlbums) dcop amarok collection totalAlbums ;;
#totalTracks) dcop amarok collection totalTracks ;;
#totalGenres) dcop amarok collection totalGenres ;;
#totalCompilations) dcop amarok collection totalCompilations ;;
# Collection Stats
#most_songs_by_artist) dcop amarok collection query 'SELECT t1.name FROM artist t1 INNER JOIN tags t2 ON t1.id = t2.artist GROUP BY t2.artist ORDER BY COUNT(t2.artist) DESC LIMIT 1;' ;;
#most_songs_by_artist_n) dcop amarok collection query 'SELECT count(t2.artist) FROM artist t1 INNER JOIN tags t2 ON t1.id = t2.artist GROUP BY t2.artist ORDER BY COUNT(t2.artist) DESC LIMIT 1;' ;;
#most_songs_are_genre) dcop amarok collection query 'SELECT t1.name FROM genre t1 INNER JOIN tags t2 ON t1.id = t2.genre GROUP BY t2.genre ORDER BY COUNT(t2.genre) DESC LIMIT 1;' ;;
#most_songs_are_genre_n) dcop amarok collection query 'SELECT count(t2.genre) FROM genre t1 INNER JOIN tags t2 ON t1.id = t2.genre GROUP BY t2.genre ORDER BY COUNT(t2.genre) DESC LIMIT 1;' ;;
#most_songs_during_year) dcop amarok collection query 'SELECT t1.name FROM year t1 INNER JOIN tags t2 ON t1.id = t2.year GROUP BY t2.year ORDER BY COUNT(t2.year) DESC LIMIT 1;' ;;
#most_songs_during_year_n) dcop amarok collection query 'SELECT count(t2.year) FROM year t1 INNER JOIN tags t2 ON t1.id = t2.year GROUP BY t2.year ORDER BY COUNT(t2.year) DESC LIMIT 1;' ;;
#most_albums_by_artist) dcop amarok collection query 'SELECT name FROM artist WHERE id=(SELECT t1.artist from (SELECT artist FROM tags GROUP BY album) AS t1 GROUP BY t1.artist ORDER BY count(artist) DESC LIMIT 1);' ;;
#most_albums_by_artist_n) dcop amarok collection query 'SELECT count(artist) from (SELECT artist FROM tags GROUP BY album) AS t1 GROUP BY t1.artist ORDER BY count(artist) DESC LIMIT 1;' ;;
#most_albums_are_genre) dcop amarok collection query 'SELECT name FROM genre WHERE id=(SELECT t1.genre from (SELECT genre FROM tags GROUP BY album) AS t1 GROUP BY t1.genre ORDER BY count(genre) DESC LIMIT 1);' ;;
#most_albums_are_genre_n) dcop amarok collection query 'SELECT count(genre) from (SELECT genre FROM tags GROUP BY album) AS t1 GROUP BY t1.genre ORDER BY count(genre) DESC LIMIT 1;' ;;
#most_albums_during_year) dcop amarok collection query 'SELECT name FROM year WHERE id=(SELECT t1.year from (SELECT year FROM tags GROUP BY album) AS t1 GROUP BY t1.year ORDER BY count(year) DESC LIMIT 1);' ;;
#most_albums_during_year_n) dcop amarok collection query 'SELECT count(year) from (SELECT year FROM tags GROUP BY album) AS t1 GROUP BY t1.year ORDER BY count(year) DESC LIMIT 1;' ;;
esac
As you can see, I am just trying to adapt an amarok1 script.
Thanks a lot.
Offline
Here's what I used (Python); sorry it's a bit messy:
#!/usr/bin/env python
import dbus
wdt = 25
bus = dbus.SessionBus()
obj = bus.get_object('org.mpris.amarok', '/Player')
mtd = obj.get_dbus_method('GetMetadata', 'org.freedesktop.MediaPlayer')
nfo = mtd()
if nfo.has_key('title'):
print "\n"
print nfo['title'].center(wdt)
if nfo['artist'] != "": print nfo['artist'].center(wdt)
if nfo['album'] != "": print nfo['album'].center(wdt)
You can always get more information than what I have there. Just use any DBUS viewer (qdbusviewer is pretty nice) and you'll find out what you can display.
-- jwc
http://jwcxz.com/ | blog
dotman - manage your dotfiles across multiple environments
icsy - an alarm for powernappers
Offline
Thanks, it seems that the progress of the song is not displayed in dbus, so I guess that it is impossible.
Offline
Actually, it's in Player/ with method PositionGet.
It returns the number of milliseconds that have elapsed.
You can get the total time from the object that GetMetadata returns under the index mtime.
Edit: quick 'n' dirty script to display the percent of the song completed:
#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
obj = bus.get_object('org.mpris.amarok', '/Player')
mtd = obj.get_dbus_method('GetMetadata', 'org.freedesktop.MediaPlayer')
nfo = mtd()
if nfo.has_key('mtime') and nfo['mtime'] != 0:
a = obj.get_dbus_method('PositionGet', 'org.freedesktop.MediaPlayer')
b = a()
print float(b) / float(nfo['mtime'])*100
Just use that in combination with ${execbar [script]} and you have a nice progress bar.
Last edited by jwcxz (2009-05-17 16:57:19)
-- jwc
http://jwcxz.com/ | blog
dotman - manage your dotfiles across multiple environments
icsy - an alarm for powernappers
Offline
Pages: 1