From d03d6e606b40157d910ddf99ab018156abeb8ef0 Mon Sep 17 00:00:00 2001 From: "berkeviktor@aol.com" Date: Mon, 28 Feb 2011 18:59:32 +0100 Subject: add wdk changes to named branch --- plugins/mpcinfo/functions.c | 167 ++++++++++++++++++++ plugins/mpcinfo/makefile.mak | 18 +++ plugins/mpcinfo/mp3Info.c | 361 +++++++++++++++++++++++++++++++++++++++++++ plugins/mpcinfo/mpcInfo.c | 149 ++++++++++++++++++ plugins/mpcinfo/oggInfo.c | 122 +++++++++++++++ plugins/mpcinfo/theme.c | 136 ++++++++++++++++ 6 files changed, 953 insertions(+) create mode 100644 plugins/mpcinfo/functions.c create mode 100644 plugins/mpcinfo/makefile.mak create mode 100644 plugins/mpcinfo/mp3Info.c create mode 100644 plugins/mpcinfo/mpcInfo.c create mode 100644 plugins/mpcinfo/oggInfo.c create mode 100644 plugins/mpcinfo/theme.c (limited to 'plugins/mpcinfo') diff --git a/plugins/mpcinfo/functions.c b/plugins/mpcinfo/functions.c new file mode 100644 index 00000000..ed0632d4 --- /dev/null +++ b/plugins/mpcinfo/functions.c @@ -0,0 +1,167 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* +typedef int (*MYPROC)(HWND,HWND,char*,char*,BOOL,BOOL); + +int dllProc(char *name, char *data){ + HINSTANCE hinstLib; + hinstLib = LoadLibrary("mpcinfo"); + //MYPROC proc; + int res; + if (hinstLib != NULL){ + //proc = ; + if ((MYPROC) GetProcAddress(hinstLib, name)!=NULL){ + res=(MYPROC)(NULL,NULL,data,NULL,TRUE,TRUE); + } + else{fprintf(stderr,"can't get proc: %s\n",name);res=-2;} + } + else{fprintf(stderr,"can't access dll\n");return -1;} + FreeLibrary(hinstLib); + return res; +} +*/ + +/* +int dllProc(char *name, char *data) +{ + static HMODULE lib = NULL; + if (!lib) + { + lib = LoadLibraryA ("mpcinfo"); + if (!lib) + { + return FALSE; + } + FreeLibrary (lib); + } + + return TRUE; +} +*/ + +char *split(char *text, char seperator){ + //if (DEBUG==1) putlog("splitting"); + int i;int pos=-1; + for (i=0;i=0;i--){ + if (ret[i]==32) ret[i]=0; + else i=-1; + } + } + //if (DEBUG==1) putlog("substring created"); + return ret; +} + +static char *substring(char *text, int first, int length){return subString(text,first,length,0);} + + +char *readLine(FILE *f){ + //if (DEBUG==1) putlog("reading line from file"); + char *buffer=(char*)calloc(1024,sizeof(char)); //malloc(sizeof(char)*1024); + int pos=0; + int cc=0; + while((cc!=EOF)&&(pos<1024)&&(cc!=10)){ + cc=fgetc(f); + if ((cc!=10)&&(cc!=13)){ + if (cc==EOF) buffer[pos]=0; + else buffer[pos]=(char)cc;pos++; + } + } + if (buffer[pos]==EOF) xchat_printf(ph,"EOF: %i\n",pos); + return buffer; +} + +char *toUpper(char *text){ + //if (DEBUG==1) putlog("converting text to upper case"); + char *ret=(char*) calloc(strlen(text)+1,sizeof(char)); + int i; + for (i=0;i mpcinfo.def + echo xchat_plugin_init >> mpcinfo.def + echo xchat_plugin_deinit >> mpcinfo.def + +mpcinfo.obj: mpcinfo.c makefile.mak + cl $(CFLAGS) $(GLIB) /I.. mpcinfo.c + +clean: + del *.obj + del *.dll + del *.exp + del *.lib diff --git a/plugins/mpcinfo/mp3Info.c b/plugins/mpcinfo/mp3Info.c new file mode 100644 index 00000000..f75ba9c4 --- /dev/null +++ b/plugins/mpcinfo/mp3Info.c @@ -0,0 +1,361 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//#include +#include +//#include "functions.c" + +struct tagInfo{ + int mode; + int cbr; + int bitrate; + unsigned int freq; + char *artist; + char *title; + char *album; + char *comment; + char *genre; + //int genre; + //int track; +}; + +static int RATES[2][3][15]={ + {//mpeg2 + {-1,8,16,24,32,64,80,56,64,128,160,112,128,256,320},//layer3 (V2) + {-1,32,48,56,64,80,96,112,128,160,192,224,256,320,384},//layer2 (V2) + {-1,32,64,96,128,160,192,224,256,288,320,352,384,416,448},//layer1 (V2) + }, + {//mpeg1 + {-1,32,40,48,56,64,80,96,112,128,160,192,224,256,320},//layer3 (V1) + {-1,32,48,56,64,80,96,112,128,160,192,224,256,320,384},//layer2 (V1) + {-1,32,64,96,128,160,192,224,256,288,320,352,384,416,448},//layer1 (V1) + }}; +static int FREQS[2][4]={{22050,24000,16000,-1},{44100,48000,32000,-1}}; +//static double FRATES[]={38.5,32.5,27.8,0.0}; + +static char GENRES[][50]={"Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge","Hip-Hop","Jazz","Metal", +"New Age","Oldies","Other","Pop","R&B","Rap","Reggae","Rock","Techno","Industrial", +"Alternative","Ska","Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient","Trip-Hop","Vocal","Jazz+Funk", +"Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise", +"AlternRock","Bass","Soul","Punk","Space","Meditative","Instrumental Pop","Instrumental Rock","Ethnic","Gothic", +"Darkwave","Techno-Industrial","Electronic","Pop-Folk","Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta", +"Top 40","Christian Rap","Pop/Funk","Jungle","Native American","Cabaret","New Wave","Psychadelic","Rave","Showtunes", +"Trailer","Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro","Musical","Rock & Roll","Hard Rock", + +//################## END OF OFFICIAL ID3 TAGS, WINAMP TAGS BELOW ######################################## + +"Folk","Folk/Rock","National Folk","Swing","Fast Fusion","Bebob","Latin","Revival","Celtic","Bluegrass", +"Avantgarde","Gothic Rock","Progressive Rock","Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band","Chorus","Easy Listening","Acoustic", +"Humour","Speech","Chanson","Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus","Porn Groove", +"Satire","Slow Jam","Club","Tango","Samba","Folklore","Ballad","Poweer Ballad","Rhytmic Soul","Freestyle", +"Duet","Punk Rock","Drum Solo","A Capela","Euro-House","Dance Hall", + +//################## FOUND AT http://en.wikipedia.org/wiki/ID3 ########################################### + +"Goa","Drum & Bass","Club-House","Hardcore", +"Terror","Indie","BritPop","Negerpunk","Polsk Punk","Beat","Christian Gangsta Rap","Heavy Metal","Black Metal","Crossover", +"Contemporary Christian","Christian Rock","Merengue","Salsa","Thrash Metal","Anime","JPop","Synthpop" + +}; + +static char MODES [][13]={"Stereo","Joint-Stereo","Dual-Channel","Mono"}; + +int iPow(int x, int y){return (int)(pow((double)x,(double) y));} + +int str2int(char *text){ + //if (DEBUG==1) putlog("converting string to int"); + int i; + int ret=0; + for (i=1;i<=strlen(text);i++){ + if ((text[strlen(text)-i]>57)||(text[strlen(text)-i]<48)){ + xchat_printf(ph,"invalid char in string: %i",text[strlen(text)-i]); + return 255; + } + ret+=((int)text[strlen(text)-i]-48)*iPow(10,i-1); + } + //xchat_printf(ph, "str2int(%s)=%i",text,ret); + //if (DEBUG==1) putlog("int converted"); + return ret; +} +/* +static int getSize(char *file){ + //if (DEBUG==1) putlog("reading filesize"); + struct stat info; + if (stat(file,&info)!=0) return -1; + return info.st_size; +}*/ +/* +int inStr(char *s1, int sl1, char *s2){ + //if (DEBUG==1) putlog("checking instr"); + int i;int j; + for(i=0;i=0;i--){ + if (ret[i]==32) ret[i]=0; + else i=-1; + } + } + //if (DEBUG==1) putlog("substring created"); + return ret; +} + +static char *substring(char *text, int first, int length){return subString(text,first,length,0);} //1 +*/ + +static char *tagExtract(char *tag, int tagLen, char* info){ +//if (DEBUG==1) putlog("extracting tag"); + int pos, len, i; + pos=inStr(tag,tagLen,info); +//xchat_printf(ph,"pos=%i",pos); + if (pos==-1) return "";//NULL; + //printf("position of %s = %i\n",info,pos); + len=0; + //for (i=pos;i=0)) + ret.genre=GENRES[val];//#############changed + else { + ret.genre="unknown"; + //xchat_printf(ph, "tmp[0]=%i (%i)",val,tmp[0]); + } + //xchat_printf(ph, "tmp: \"%s\" -> %i",tmp,tmp[0]); + //xchat_printf(ph,"genre \"%s\"",ret.genre); + //if (DEBUG==1) putlog("id3v1 extracted"); + return ret; +} + +char *extractID3Genre(char *tag){ + //if (DEBUG==1) putlog("extracting id3 genre"); + if (tag[strlen(tag)-1]==')'){ + tag[strlen(tag)-1]=0; + tag=&tag[1]; + return GENRES[str2int(tag)]; + //return tag; + } + else{ + int i; + //xchat_print(ph, "Using 2 criteria"); + for (i=0;i>3; + layerB=(header[1]&6)>>1; + bitrateB=(header[2]&240)>>4; //4 + freqB=(header[2]&12)>>2;//2 + modeB=(header[3]&192)>>6;//6 + //printf("Mpeg: %i\nLayer: %i\nBitrate: %i\nFreq: %i\nMode: %i\n",versionB, layerB, bitrateB, freqB, modeB); + //int Bitrate=RATES[versionB][layerB-1][bitrateB]; + //int Freq=FREQS[versionB][freqB]; + info.bitrate=RATES[versionB][layerB-1][bitrateB]; + info.freq=FREQS[versionB][freqB]; + info.mode=modeB; + } + fclose(f); + //if (DEBUG==1) putlog("header readed"); + return info; +} +/* +static void printMp3Info(char *file){ + //printf("\nScanning Mp3-File for Informations: %s\n",file); + //printf("size:\t%10d byte\n",getSize(file)); + struct tagInfo info =readHeader(file); + printf("%s | %10d",file,getSize(file)); + if (info.bitrate>0){ + //printf("Bitrate: %i\nFreq: %i\nMode: %s\n",info.bitrate,info.freq,MODES[info.mode]); + printf(" | %i kbps | %i kHz | %s",info.bitrate,info.freq,MODES[info.mode]); + //if (info.artist!=NULL) printf("\nArtist: %s\nTitle: %s\nAlbum: %s\nComment: %s\nGenre: %s\n",info.artist,info.title,info.album,info.comment,info.genre); + if (info.artist!=NULL) { + printf("| %s | %s | %s | %s | %s",info.artist,info.title,info.album,info.comment,info.genre); + //printf("| %s ",info.title);//,info.title,info.album,info.comment,info.genre + } + } + printf("\n"); + +} +*/ diff --git a/plugins/mpcinfo/mpcInfo.c b/plugins/mpcinfo/mpcInfo.c new file mode 100644 index 00000000..e467e516 --- /dev/null +++ b/plugins/mpcinfo/mpcInfo.c @@ -0,0 +1,149 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//static int DEBUG=0; +static char *VERSION="0.0.6"; + +#include +#include +#include +#include +#include +#include +#include "xchat-plugin.h" +static xchat_plugin *ph; + +#include "functions.c" +#include "mp3Info.c" +#include "oggInfo.c" +#include "theme.c" + +static int print_themes (char *word[], char *word_eol[], void *userdata){ + printThemes(); + return XCHAT_EAT_ALL; +} + +static int mpc_themeReload(char *word[], char *word_eol[], void *userdata){ + themeInit(); + loadThemes(); + return XCHAT_EAT_ALL; +} + +static int mpc_tell(char *word[], char *word_eol[], void *userdata){ + char *tTitle, *zero, *oggLine, *line; + struct tagInfo info; + HWND hwnd = FindWindow("MediaPlayerClassicW",NULL); + if (hwnd==0) {xchat_command(ph, randomLine(notRunTheme));return XCHAT_EAT_ALL;} + + tTitle=(char*)malloc(sizeof(char)*1024); + GetWindowText(hwnd, tTitle, 1024); + zero=strstr(tTitle," - Media Player Classic"); + if (zero!=NULL) zero[0]=0; + else xchat_print(ph,"pattern not found"); + + if ((tTitle[1]==':')&&(tTitle[2]=='\\')){ + //xchat_print(ph,"seams to be full path"); + if (endsWith(tTitle,".mp3")==1){ + //xchat_print(ph,"seams to be a mp3 file"); + info = readHeader(tTitle); + + if ((info.artist!=NULL)&&(strcmp(info.artist,"")!=0)){ + char *mode=MODES[info.mode]; + //xchat_printf(ph,"mode: %s\n",mode); + char *mp3Line=randomLine(mp3Theme); + mp3Line=replace(mp3Line,"%art",info.artist); + mp3Line=replace(mp3Line,"%tit",info.title); + mp3Line=replace(mp3Line,"%alb",info.album); + mp3Line=replace(mp3Line,"%com",info.comment); + mp3Line=replace(mp3Line,"%gen",info.genre); + //mp3Line=replace(mp3Line,"%time",pos); + //mp3Line=replace(mp3Line,"%length",len); + //mp3Line=replace(mp3Line,"%ver",waVers); + //mp3Line=intReplace(mp3Line,"%br",br); + //mp3Line=intReplace(mp3Line,"%frq",frq); + + mp3Line=intReplace(mp3Line,"%br",info.bitrate); + mp3Line=intReplace(mp3Line,"%frq",info.freq); + mp3Line=replace(mp3Line,"%mode",mode); + //mp3Line=replace(mp3Line,"%size",size); + //mp3Line=intReplace(mp3Line,"%perc",perc); + //mp3Line=replace(mp3Line,"%plTitle",title); + mp3Line=replace(mp3Line,"%file",tTitle); + xchat_command(ph, mp3Line); + return XCHAT_EAT_ALL; + } + } + if (endsWith(tTitle,".ogg")==1){ + xchat_printf(ph,"Ogg detected\n"); + info = getOggHeader(tTitle); + if (info.artist!=NULL){ + char *cbr; + if (info.cbr==1) cbr="CBR"; else cbr="VBR"; + oggLine=randomLine(oggTheme); + //if (cue==1) oggLine=cueLine; + //xchat_printf(ph,"ogg-line: %s\n",oggLine); + oggLine=replace(oggLine,"%art",info.artist); + oggLine=replace(oggLine,"%tit",info.title); + oggLine=replace(oggLine,"%alb",info.album); + oggLine=replace(oggLine,"%com",info.comment); + oggLine=replace(oggLine,"%gen",info.genre); + //oggLine=replace(oggLine,"%time",pos); + //oggLine=replace(oggLine,"%length",len); + //oggLine=replace(oggLine,"%ver",waVers); + oggLine=intReplace(oggLine,"%chan",info.mode); + oggLine=replace(oggLine,"%cbr",cbr); + oggLine=intReplace(oggLine,"%br",info.bitrate/1000);//br); + oggLine=intReplace(oggLine,"%frq",info.freq); + //oggLine=replace(oggLine,"%size",size); + //oggLine=intReplace(oggLine,"%perc",perc); + //oggLine=replace(oggLine,"%plTitle",title); + oggLine=replace(oggLine,"%file",tTitle); + xchat_command(ph, oggLine); + return XCHAT_EAT_ALL; + } + } + } + line=randomLine(titleTheme); + line=replace(line,"%title", tTitle); + xchat_command(ph,line); + return XCHAT_EAT_ALL; +} + +int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg){ + ph = plugin_handle; + *plugin_name = "mpcInfo"; + *plugin_desc = "Information-Script for Media Player Classic"; + *plugin_version=VERSION; + + xchat_hook_command(ph, "mpc", XCHAT_PRI_NORM, mpc_tell,"no help text", 0); + xchat_hook_command(ph, "mpc_themes", XCHAT_PRI_NORM, print_themes,"no help text", 0); + xchat_hook_command(ph, "mpc_reloadthemes", XCHAT_PRI_NORM, mpc_themeReload,"no help text", 0); + xchat_command (ph, "MENU -ietc\\music.png ADD \"Window/Display Current Song (MPC)\" \"MPC\""); + + themeInit(); + loadThemes(); + xchat_printf(ph, "%s %s plugin loaded\n",*plugin_name, VERSION); + + return 1; +} + +int +xchat_plugin_deinit (void) +{ + xchat_command (ph, "MENU DEL \"Window/Display Current Song (MPC)\""); + xchat_print (ph, "mpcInfo plugin unloaded\n"); + return 1; +} diff --git a/plugins/mpcinfo/oggInfo.c b/plugins/mpcinfo/oggInfo.c new file mode 100644 index 00000000..83c2beb5 --- /dev/null +++ b/plugins/mpcinfo/oggInfo.c @@ -0,0 +1,122 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +static int getOggInt(char *buff, int beg, int bytes){ +//if (DEBUG==1) putlog("getOggInt"); + int ret=0; + int i; + for (i=0;i=0) ret+=buff[i+beg]*iPow(256,i);else ret+=(256+buff[i+beg])*iPow(256,i); + //printf("[%i]=%i\n",i,buff[i+beg]); + } + return ret; +} + +static char *upperStr(char *text){ +//if (DEBUG==1) putlog("converting text to uc"); + //printf("upperStr(%s)\n",text); + int i; + char *ret=(char*) malloc(sizeof(char)*(strlen(text)+1)); + ret[strlen(text)]=0; + for (i=0;i + +struct theme{ + int size; + char **line; +}; + +static struct theme notRunTheme; +static struct theme titleTheme; +static struct theme mp3Theme; +static struct theme oggTheme; + + +void themeInit(){ + //if (DEBUG==1) putlog("init theme"); + /*mp3Theme.size=0;oggTheme.size=0;cueTheme.size=0;streamTheme.size=0;etcTheme.size=0; + stopTheme.size=0;pauseTheme.size=0;*/ + + notRunTheme.size=0;titleTheme.size=0; + srand((unsigned int)time((time_t *)NULL)); + //if (DEBUG==1) putlog("theme init done"); +} + +void printTheme(struct theme data){ + int i; + for (i=0;i 0) + { + line=" "; + } else + { + line="\0"; + } + + while (line[0]!=0) + { + line=readLine(f); + val=split(line,'='); + printf("line: %s\n",line); + printf("val: %s\n",val); + if (strcmp(toUpper(line),"OFF_LINE")==0) notRunTheme=themeAdd(notRunTheme,val); + if (strcmp(toUpper(line),"TITLE_LINE")==0) titleTheme=themeAdd(titleTheme,val); + if (strcmp(toUpper(line),"MP3_LINE")==0) mp3Theme=themeAdd(mp3Theme,val); + if (strcmp(toUpper(line),"OGG_LINE")==0) mp3Theme=themeAdd(oggTheme,val); + } + fclose(f); + xchat_print(ph, "theme loaded successfull\n"); + } + if (notRunTheme.size==0) notRunTheme=themeAdd(notRunTheme,"say Media Player Classic not running"); + if (titleTheme.size==0) titleTheme=themeAdd(titleTheme,"say Playing %title in Media Player Classic"); + if (mp3Theme.size==0) mp3Theme=themeAdd(mp3Theme,"me listens to %art with %tit from %alb [%gen|%br kbps|%frq kHz|%mode] in Media Player Classic "); + if (oggTheme.size==0) oggTheme=themeAdd(oggTheme,"me listens to %art with %tit from %alb [%gen|%br kbps|%frq kHz|%chan channels] in Media Player Classic "); + //mp3Theme=themeAdd(mp3Theme,"me listens to %art with %tit from %alb [%time|%length|%perc%|%br kbps|%frq kHz|%mode] in Media Player Classic "); +} + +int rnd(int max){ + return rand()%max; +} + +char *randomLine(struct theme data){ + return data.line[rnd(data.size)]; +} -- cgit 1.4.1