%
% anyremote configuration file for amarok management. (Server-mode)
% v.3 - Improved cover art + library access
% Made by Carlos Sanchez (chukysoria@gmail.com)
%

% STATUS stable
% XTE no
% SOUND app
% ENV no

GuiAppName=Amarok v.3/KDE3
GuiAppBinary=amarok
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
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=Server
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 supports cover art. This configuration file is for Amarok/KDE3

[Protocol]=Server

(Init)=Include($(CfgDir)/Utils/aliases-server.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);\
	Exec(echo 'P=`which convert 2> /dev/null|grep convert|grep -v no|wc -l|tr -d " "`;if [ "x$P" == "x1" ]; then true; else $(CfgDir)/Utils/message.sh "ERROR: ImageMagic is not installed"; fi'|bash -f -s);\
	Make(var,arDir,echo $HOME/.anyRemote/);\
	Make(var,cvDir,by_value,$(arDir)amarok_covers/);

(Connect)=Set(parameter,debug,on);\
	Make(mode,amarok-v3);

AM_HELP=Set(text,replace,Help,Manage player by joystick or from menu);

AMAROK_V2_SETINFO=ExecAndSet(title,echo 'T=`dcop amarok player title`;A=`dcop amarok player artist`;echo $T by $A'|bash -f -s);\
	ExecAndSet(status,dcop amarok player totalTime);\
	ExecAndSet(cover, noname,echo 'I=`dcop amarok player coverImage`;F=`basename $I`;convert \( $I -resize $(cover_size)x$(cover_size) \) \( +clone -flip -crop x39.86% -composite \) -append $(cvDir)$F;echo $(cvDir)$F;'|bash -f -s);
AMAROK_V2_START_TIMER=Macro(AMAROK_V2_SETINFO);\
	Timer(AMAROK_V2_SETINFO,5,0);
AMAROK_V2_STOP_TIMER =Timer(AMAROK_V2_SETINFO,cancel);


[Mode]=amarok-v3

AM_V2_LAYOUT=Set(icons,Amarok,1,prev,2,rewind,3,play,4,pause,5,stop,6,forward,7,next,8,none,9,none,*,none,0,none,#,none);Set(font,small);Set(layout,bottomline,joystick_only,choose,3,volume,ticker,up,Vol+,down,Vol-);
AM_V2_RUN_IF=Exec(echo 'A=`dcop 2> /dev/null|grep amarok`; if [ "x$A" == "x" ]; then amarok& fi' | bash -f -s);
AM_V2_MENU=Set(menu,replace,Playlist,Mute,Collection Browser,Run Player,Quit Player,Toggle Fullscreen,Help);Macro(ALLIN1MENU);Macro(VOL_SET);

(EnterMode)=Macro(AM_V2_LAYOUT);\
	Macro(AM_V2_RUN_IF);\
	Exec(rm -rf $(cvDir);mkdir $(cvDir));\
	Make(var,cover_size,echo 64);\
	Get(cover_size);\
	Macro(AMAROK_V2_SETINFO);\
	Macro(AM_V2_MENU);\
	Macro(AMAROK_V2_START_TIMER);

Cancel=Exec(rm -rf $(cvDir));
(Disconnect)=Macro(AMAROK_V2_STOP_TIMER);

Back=Set(text,close);Macro(AM_V2_MENU);

Playlist=Macro(AMAROK_V2_STOP_TIMER);Make(mode,amarok_playlist_v2)
Collection Browser=Macro(AMAROK_V2_STOP_TIMER);Make(mode,amarok_collection_browser_v2)

Vol+=Exec(dcop amarok player volumeUp);Macro(VOL_SET);
Vol-=Exec(dcop amarok player volumeDown);Macro(VOL_SET);

Mute=Exec(dcop amarok player mute);Set(volume,0);Set(menu,replace,Playlist,Vol+,Vol-,Unmute,File Browser,Collection Browser,Run Player,Quit Player,Toggle Fullscreen,Help);Macro(ALLIN1MENU);
Unmute=Exec(dcop amarok player mute);Macro(AM_V2_MENU);
Toggle Fullscreen=Set(fullscreen,toggle);Set(cover,clear);Get(cover_size);

CoverSize($$)=\
    Make(var,cover_size,by_value,$(Index));\
    Exec(echo $(arDir) > $HOME/.anyRemote/cover_size);

Run Player=Macro(AM_V2_RUN_IF);
Quit Player=Exec(dcop amarok MainApplication-Interface quit);Macro(AMAROK_V2_STOP_TIMER);Set(title,);Set(status,);
Help=Macro(AM_HELP);

VOL_SET=ExecAndSet(volume,dcop amarok player getVolume);

% No more 7 buttons - Nokias Series40 has 160x120 screens 
1=Exec(dcop amarok player prev);Macro(AMAROK_V2_SETINFO);
2=Exec(dcop amarok player seekRelative -10) 
3=Exec(dcop amarok player play);Macro(AMAROK_V2_START_TIMER);Macro(VOL_SET);

4=Exec(dcop amarok player pause);Macro(AMAROK_V2_STOP_TIMER);Set(title,Paused);
5=Exec(dcop amarok player stop);Set(title,Stopped);Macro(AMAROK_V2_STOP_TIMER);
6=Exec(dcop amarok player seekRelative 10) 

7=Exec(dcop amarok player next);Macro(AMAROK_V2_SETINFO);

[ModeEnd]

[Mode]=amarok_playlist_v2
(EnterMode)=Set(list,font,small);Set(list,bg,54,73,135);Set(list,fg,141,159,218);ExecAndSet(list,replace,Playlist,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;s/,/ /g;s/$/,/');Set(menu,add,Play);
(ExitMode)=Set(list,close);Macro(AMAROK_V2_START_TIMER);

Back($$)=Make(mode,amarok-v3);
Play($$)=Exec(dcop amarok playlist playByIndex `expr $(Index) - 1`);
[ModeEnd]

[ModeEnd]

[Mode]=amarok_collection_browser_v2

(EnterMode)=Set(list,font,small);Set(list,bg,54,73,135);Set(list,fg,141,159,218);Macro(FILLLIST_ARTIST);Macro(UPDATEMENU_ARTIST);
(ExitMode)=Set(list,close);

UPDATEMENU_ARTIST=Set(menu,replace,View Albums,Play Artist,Add Artist,Find);
FILLLIST_ARTIST=ExecAndSet(list,replace,Artists,dcop amarok collection query "SELECT name FROM artist"|sed "s/\*//"|sed "s/$/,/");

View Albums($$)=Make(var,current_artist,by_value,$(Param));Make(var,current_artist_index,by_value,$(Index));Set(list,replace,Albums by $(Param),..);Macro(UPDATEMENU_ALBUM);Macro(FILLLIST_ALBUM)

Play Artist($$)=Exec(dcop amarok playlist clearPlaylist; dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.artist in (select id from artist where name = '$(Param)')"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"> $(arDir)file_route;sh $(arDir)file_route; dcop amarok playlist playByIndex 0);

Add Artist($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.artist in (select id from artist where name = '$(Param)')"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"> $(arDir)file_route;sh $(arDir)file_route);

Find($$)=Make(mode,amarok_find_song);

UPDATEMENU_ALBUM=Set(menu,replace,View Songs,Play Album,Add Album);
FILLLIST_ALBUM=ExecAndSet(list,add,SAME,dcop amarok collection query "select distinct a.name from album a, tags b where a.id = b.album and b.artist in (select id from artist where name = '$(current_artist)')"|sed "s/\*//"|sed "s/$/,/")

View Songs(..)=Macro(FILLLIST_ARTIST);Macro(UPDATEMENU_ARTIST);Set(list,select,$(current_artist_index));
View Songs($$)=Make(var,current_album,by_value,$(Param));Make(var,current_album_index,by_value,$(Index));Set(list,replace,Songs of $(Param),..);Macro(UPDATEMENU_SONGS);Macro(FILLLIST_SONGS)

Play Album($$)=Exec(dcop amarok playlist clearPlaylist; dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.album in (select id from album where name = '$(Param)')"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $(arDir)file_route;sh $(arDir)file_route; dcop amarok playlist playByIndex 0);

Add Album($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.album in (select id from album where name = '$(Param)')"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $(arDir)file_route;sh $(arDir)file_route);

UPDATEMENU_SONGS=Set(menu,replace,Add to playlist,Add all,Queue,Play,Only by Artist);
FILLLIST_SONGS=ExecAndSet(list,add,SAME,dcop amarok collection query "SELECT DISTINCT t.title FROM tags t where t.album in (select id from album where name = '$(current_album)')"|sed "s/\*//"|sed "s/$/,/")

Add to playlist(..)=Set(list,replace,Albums by $(current_artist),..);Macro(FILLLIST_ALBUM);Macro(UPDATEMENU_ALBUM);Set(list,select,$(current_album_index));
Add to playlist($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.album in (select id from album where name = '$(current_album)') and  t.title = '$(Param)'"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $(arDir)file_route;sh $(arDir)file_route);

Add all($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.album in (select id from album where name = '$(current_album)')"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $(arDir)file_route;sh $(arDir)file_route);

Queue($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.album in (select id from album where name = '$(current_album)') and  t.title = '$(Param)'"|sed "s/.\//dcop amarok playlist queueMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $(arDir)file_route;sh $(arDir)file_route);

Play($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.album in (select id from album where name = '$(current_album)') and  t.title = '$(Param)'"|sed "s/.\//dcop amarok playlist playMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $(arDir)file_route;sh $(arDir)file_route);

Only by Artist($$)=Set(list,replace,SAME,..);Macro(UPDATEMENU_SONGS_ARTIST);Macro(FILLLIST_SONGS_ARTIST)

UPDATEMENU_SONGS_ARTIST=Set(menu,replace,Add to playlist,Add all,Queue,Play,All Album Songs);
FILLLIST_SONGS_ARTIST=ExecAndSet(list,add,SAME,dcop amarok collection query "SELECT DISTINCT t.title FROM tags t where t.album in (select id from album where name = '$(current_album)') and t.artist in (select id from artist where name = '$(current_artist)')"|sed "s/\*//"|sed "s/$/,/")

All Album Songs($$)=Set(list,replace,SAME,..);Macro(UPDATEMENU_SONGS);Macro(FILLLIST_SONGS)
Back($$)=Make(mode,amarok-v3);

[ModeEnd]


[Mode]=amarok_find_song

(EnterMode)=Set(editfield,Find,Enter song name,);
(ExitMode)=Set(list,close);

Ok($$)=Make(var,search,by_value,$(Param));Set(list,add,Songs found,..);Macro(UPDATEMENU_SONGS2);Macro(FILLLIST_SONGS2)
Back($$)=Make(mode,amarok_collection_browser_v2);


UPDATEMENU_SONGS2=Set(menu,replace,Add to playlist,Add all,Queue,Play,Find);
FILLLIST_SONGS2=ExecAndSet(list,replace,SAME,dcop amarok collection query "SELECT DISTINCT t.title FROM tags t where t.title like '%$(search)%' order by t.title"|sed "s/\*//"|sed "s/$/,/")


Add to playlist($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.title = '$(Param)'"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $HOME/.anyRemote/file_route;sh $HOME/.anyRemote/file_route);

Add all($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.title like '%$(search)%'"|sed "s/.\//dcop amarok playlist addMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $HOME/.anyRemote/file_route;sh $HOME/.anyRemote/file_route);

Queue($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.title = '$(Param)'"|sed "s/.\//dcop amarok playlist queueMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $HOME/.anyRemote/file_route;sh $HOME/.anyRemote/file_route);

Play($$)=Exec(dcop amarok collection query "SELECT DISTINCT t.url FROM tags t where t.title = '$(Param)'"|sed "s/.\//dcop amarok playlist playMedia \"file:\/\/\//"|sed "s/$/\"/"|sed "s/#/&23/"> $HOME/.anyRemote/file_route;sh $HOME/.anyRemote/file_route);

Find($$)=Set(editfield,Enter song name,Find Song,);

[ModeEnd]
[End]
