summaryrefslogtreecommitdiff
path: root/watrack_mpd/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'watrack_mpd/main.c')
-rwxr-xr-xwatrack_mpd/main.c138
1 files changed, 119 insertions, 19 deletions
diff --git a/watrack_mpd/main.c b/watrack_mpd/main.c
index aa7aeef..ce0f60b 100755
--- a/watrack_mpd/main.c
+++ b/watrack_mpd/main.c
@@ -19,16 +19,23 @@
#include "commonheaders.h"
+void Start();
+
LPINITPROC Init()
{
+ Start();
return 0;
}
+void Stop();
LPDEINITPROC DeInit()
{
+ Stop();
return 0;
}
LPCHECKPROC CheckPlayer(HWND wnd, int flags)
{
+ if(Connected)
+ return (LPCHECKPROC)1;
return 0;
}
LPGETSTATUSPROC GetStatus()
@@ -39,8 +46,42 @@ LPNAMEPROC GetFileName(HWND wnd, int flags)
{
return 0;
}
-LPINFOPROC GetPlayerInfo(LPSONGINFO Info, int flags)
+SONGINFO SongInfo = {0};
+LPINFOPROC GetPlayerInfo(LPSONGINFO info, int flags)
{
+/* info->album = SongInfo.album;
+ info->artist = SongInfo.artist;
+ info->channels = SongInfo.channels;
+ info->codec = SongInfo.codec;
+ info->comment = SongInfo.comment;
+ info->cover = SongInfo.cover;
+ info->date = SongInfo.date;
+ info->fps = SongInfo.fps;
+ info->fsize = SongInfo.fsize;
+ info->genre = SongInfo.genre;
+ info->icon = SongInfo.icon;
+ info->kbps = SongInfo.kbps;
+ info->khz = SongInfo.khz;
+ info->lyric = SongInfo.lyric;
+ info->mfile = SongInfo.mfile;
+ info->player = SongInfo.player;
+ info->plyver = SongInfo.plyver;
+ info->status = SongInfo.status;
+ info->time = SongInfo.time;
+ info->title = SongInfo.title;
+ info->total = SongInfo.total;
+ info->track = SongInfo.track;*/
+ info->time = SongInfo.time;
+ _tcscpy(info->mfile, SongInfo.mfile);
+ _tcscpy(info->txtver, SongInfo.txtver); //??
+/* info->url = SongInfo.url; //??
+ info->vbr = SongInfo.vbr;
+ info->volume = SongInfo.volume;
+ info->year = SongInfo.year;*/
+ free(SongInfo.txtver);
+ free(SongInfo.mfile);
+ free(SongInfo.title);
+
return 0;
}
LPCOMMANDPROC SendCommand(HWND wnd, int command, int value)
@@ -53,44 +94,103 @@ void RegisterPlayer()
{
if(!bWatrackService)
return;
- else //для красоты
{
PLAYERCELL player = {0};
- player.Desc = "MPD desc";
+ player.Desc = "Music Player Daemon";
player.Check = (LPCHECKPROC)CheckPlayer;
player.Init = (LPINITPROC)Init;
player.DeInit = (LPDEINITPROC)DeInit;
player.GetStatus = (LPGETSTATUSPROC)GetStatus;
player.Command = (LPCOMMANDPROC)SendCommand;
- player.flags = 0;
+// player.flags = (WAT_OPT_HASURL|WAT_OPT_SINGLEINST);
player.GetName = (LPNAMEPROC)GetFileName;
player.GetInfo = (LPINFOPROC)GetPlayerInfo;
-// player.Icon =
+// player.Icon = //TODO:implement icon support
player.Notes = _T("123");
- player.URL = "http:// ?";
+ player.URL = "http://www.musicpd.org";
CallService(MS_WAT_PLAYER, (WPARAM)WAT_ACT_REGISTER, (LPARAM)&player);
}
}
-DWORD __stdcall Reciever(LPVOID lp)
+int Parser(unsigned char *buf, int len)
{
- NETLIBOPENCONNECTION nloc;
- nloc.cbSize = sizeof(NETLIBOPENCONNECTION);
- nloc.flags = 0;
- nloc.szHost = (char*)mir_u2a(UniGetContactSettingUtf(NULL, szModuleName, "Host", _T("127.0.0.1")));
- nloc.wPort = DBGetContactSettingWord(NULL, szModuleName, "Port", 6600);
- ghConnection = NetLib_CreateConnection(ghNetlibUser, &nloc);
- ghPacketReciever = CreatePacketReciever();
+ char *ptr;
+ char tmp[128];
+ int i;
+ if(ptr = strstr(buf, "MPD"))
+ {
+ Connected = TRUE;
+ ptr = &ptr[4];
+ for(i = 0; ptr[i] != '\n'; i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.txtver = (TCHAR*)mir_a2t(tmp);
+ }
+ if(ptr = strstr(buf, "file:"))
+ {
+ ptr = &ptr[6];
+ for(i = 0; ptr[i] != '\n'; i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.mfile = (TCHAR*)mir_a2t(tmp);
+ }
+ if(ptr = strstr(buf, "Time:"))
+ {
+ ptr = &ptr[6];
+ for(i = 0; ptr[i] != '\n'; i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.time = atoi(tmp);
+ }
+ if(ptr = strstr(buf, "Title:"))
+ {
+ ptr = &ptr[7];
+ for(i = 0; ptr[i] != '\n'; i++)
+ tmp[i] = ptr[i];
+ tmp[i+1] = '\0';
+ SongInfo.title = (TCHAR*)mir_a2t(tmp);
+ }
+ return len;
+}
+
+DWORD Reciever(LPVOID lp)
+{
+ NETLIBOPENCONNECTION nloc = {0};
+ NETLIBPACKETRECVER nlpr = {0};
+ int recvResult;
+ char *tmp = (char*)mir_u2a(gbHost);
+ nloc.cbSize = sizeof(nloc);
+ nloc.szHost = tmp;
+ nloc.timeout = 5;
+ nloc.wPort = gbPort;
+ ghConnection = NetLib_CreateConnection(ghNetlibUser, &nloc);
+ free(tmp);
+ nlpr.cbSize = sizeof(nlpr);
+ nlpr.dwTimeout = INFINITE;
+ ghPacketReciever = (HANDLE)CallService(MS_NETLIB_RECV,(WPARAM)ghConnection,0x2400);
+ while(ghConnection)
+ {
+ Netlib_Send(ghConnection, "currentsong\n", strlen("currentsong\n") + 1, 0);
+ Netlib_Send(ghConnection, "status\n", strlen("status\n") + 1, 0);
+ recvResult = CallService(MS_NETLIB_GETMOREPACKETS,(WPARAM)ghPacketReciever, (LPARAM)&nlpr);
+ if(recvResult == 0)
+ break;
+ if (recvResult == SOCKET_ERROR)
+ break;
+ nlpr.bytesUsed = Parser(nlpr.buffer, nlpr.bytesAvailable);
+ }
return 0;
}
-int Start(WPARAM wParam,LPARAM lParam)
+
+void Start()
{
DWORD pid;
- ghRecieverThread = CreateThreadEx((pThreadFuncEx)Reciever, (HANDLE)wParam, &pid);
- return 0;
+ ghRecieverThread = CreateThreadEx((pThreadFuncEx)Reciever, 0, &pid);
}
-int Stop(WPARAM wParam,LPARAM lParam)
+void Stop()
{
- return 0;
+ if(ghNetlibUser && (ghNetlibUser != INVALID_HANDLE_VALUE))
+ CallService(MS_NETLIB_SHUTDOWN,(WPARAM)ghNetlibUser,0);
}
+