%
% anyremote configuration file for amarok management. (Server-mode Bemused emulation)
% Prerequisites: Bemused client installed on cell phone
% tested with Jam SE 1.3 RC1
%

% STATUS stable
% XTEST no
% SOUND app
% ENV no

GuiAppName=Amarok
GuiAppBinary=amarok
GuiAppRun=echo 'A=`dcop 2> /dev/null|grep amarok`; if [ "x$A" == "x" ]; then echo NOK; else echo OK; fi'|bash -f -s
GuiAppIcon=amarok.png
GuiAppType=Application
GuiAppProtocols=Bemused
GuiAppDesc=Amarok is the music player for Linux and Unix with an intuitive interface. Amarok makes playing the music you love easier than ever before - and looks good doing it.  This configuration file is for Amarok/KDE3.
GuiAppVersion=echo 'V=`amarok -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`; if [ "x$V" == "x3" ]; then echo OK; else echo NOK; fi'|bash -f -s

[Protocol]=Bemused

(Init)=Include($(CfgDir)/Utils/aliases-bemused.cfg);\
	Exec(echo 'V=`amarok -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`;if [ "x$V" == "x4" ]; then $(CfgDir)/Utils/message.sh "ERROR: this configuration file is for KDE3"; fi'|bash -f -s);
	
(Connect)=Exec(amarok);Make(var,am_volume,dcop amarok player getVolume);

EXIT=Exec(dcop amarok MainApplication-Interface quit)  
FADE=Exec(dcop amarok player mute) 
FFWD=Exec(dcop amarok player seekRelative 10) 
INF2=Send(string,INF2ACK);Send(bytes,128,0,0,0,128,0,0,0,1,0,0);ExecAndSend(string,dcop amarok player nowPlaying);Send(bytes,0,0)
INFO=Send(string,INFOACK);Send(bytes,128,0,0,0,128,0,0,0,1,0,0);ExecAndSend(string,dcop amarok player nowPlaying)
NEXT=Exec(dcop amarok player next) 
PAUS=Exec(dcop amarok player pause) 
PLAY($$)=Macro(STRT)
STRT=Exec(dcop amarok player play)
PREV=Exec(dcop amarok player prev) 
% amarok crashes?
%REPT=Exec(echo 'S=`dcop amarok player repeatPlaylistStatus`; if [ "x$S" == "xfalse" ]; then dcop amarok player enableRepeatPlaylist true; else dcop amarok player enableRepeatPlaylist false; fi' | bash -f -s)
RWND=Exec(dcop amarok player seekRelative -10) 
SHFL=Exec(echo 'S=`dcop amarok player randomModeStatus`; if [ "x$S" == "xfalse" ]; then dcop amarok player enableRandomMode true; else dcop amarok player enableRandomMode false; fi' | bash -f -s)
STOP=Exec(dcop amarok player stop) 
VOLM($$)=Exec(dcop amarok player setVolume $(Param))

GVOL=Send(string,GVOLACK);Make(var,am_volume,echo 'V=`dcop amarok player getVolume`;echo "$V*255/100"|bc'|bash -f -s);Send(bytes,$(am_volume))
%GVOL=Send(string,GVOLNAK);

PLEN=ExecAndSend(bytes,dcop amarok playlist getTotalTrackCount|awk '{if($0>255) {b=int($0/256);a=$0-b;} else {b=$0;a=0};s=sprintf("%s,%s",a,b);print s;}');
PLST=Send(string,PLSTACK);\
	ExecAndSend(bytes,dcop amarok playlist getActiveIndex|awk '{if($0>255) {b=int($0/256);a=$0-b;} else {b=$0;a=0};s=sprintf("%s,%s",a,b);print s;}');\
	ExecAndSend(string,dcop amarok playlist saveCurrentPlaylist;grep '<item'  $HOME/.kde/share/apps/amarok/current.xml|sed 's/<item url=\"file:\/\/\(.*\)\" \(.\)*$/\1/'|xargs -i basename {}|sed 's/uniqueid=.*//g;s/%20/ /g;');\
	Send(bytes,0);
SLCT($$)=Exec(dcop amarok playlist playByIndex $(Param));

% The following is a trick. Replays are not real, just to satisfy client.
CHCK=Send(string,Y);
DINF=Send(string,DINFACK);Send(bytes,0,0,0,244,0,0,32,0,0,0,0,2);
DLST=Send(bytes,255,0,0)
DOWN=Send(bytes,0,100);Send(string,NoName)
FINF=Send(string,FINFACK);Send(bytes,0,0,0,100);
LIST=Send(bytes,255,0,0)
%SEEK=
VERS=Send(string,VERSACK);Send(bytes,1,73);

% Remuco extension
VOL($$)=Exec(dcop amarok player setVolume $(Param));Macro(GET_VOL)
JUMP($$)=Macro(SLCT)
QUEUE($$)=Macro(SLCT)
PLAYPAUSE=Macro(STRT);Macro(GET_STATUS);Macro(GET_REPEAT);Macro(GET_SHUFFLE);

RATE($$)=

SYNC=Macro(GET_VOL);Macro(GET_REPEAT);Macro(GET_SHUFFLE);Macro(GET_STATUS);Macro(GET_IDX);Macro(GET_TOTAL);\
     Send(string,Vol=$(am_volume));Send(bytes,10);\
     Send(string,Status=$(am_status));Send(bytes,10);\
     Send(string,Rpt=$(am_repeat));Send(bytes,10);\
     Send(string,Shfl=$(am_shuffle));Send(bytes,10);\
     Send(string,Idx=$(am_idx));Send(bytes,10);\
     Send(string,Total=$(am_total));Send(bytes,10);\
     Send(string,#);

GET_VOL=Make(var,am_volume,dcop amarok player getVolume);
GET_STATUS=Make(var,am_status,echo 'A=`dcop|grep amarok`; if [ "x$A" == "x" ]; then echo OFF; else P=`dcop amarok player isPlaying`; if [ "x$P" == "xtrue" ]; then  echo PLAY; else echo STOP; fi; fi' | bash -f -s);
GET_REPEAT=Make(var,am_repeat,echo 'A=`dcop amarok player repeatPlaylistStatus`; if [ "x$A" == "xtrue" ]; then echo Y; else echo N; fi;'|bash -f -s);
GET_SHUFFLE=Make(var,am_shuffle,echo 'A=`dcop amarok player randomModeStatus`; if [ "x$A" == "xtrue" ]; then echo Y; else echo N; fi;'|bash -f -s);
GET_IDX=Make(var,am_idx,dcop amarok playlist getActiveIndex);
GET_TOTAL=Make(var,am_total,dcop amarok playlist getTotalTrackCount);

GET_SONG($$)=Make(var,am_artist,dcop amarok player artist);\
     Make(var,am_title,dcop amarok player nowPlaying);\
     Make(var,am_cover,dcop amarok player coverImage);\
     Send(string,Artist=$(am_artist));Send(bytes,10);\
     Send(string,Title=$(am_title));Send(bytes,10);\
     Send(string,Cover=$(am_cover));Send(bytes,10);\
     Send(string,#);

GET_PLAYLIST=ExecAndSend(string,dcop amarok playlist saveCurrentPlaylist;grep '<item'  $HOME/.kde/share/apps/amarok/current.xml|sed 's/<item url=\"file:\/\/\(.*\)\" \(.\)*$/\1/'|xargs -i basename {}|sed 's/uniqueid=.*//g;s/%20/ /g;');\
     Send(string,#);

[End]
