X-Git-Url: http://royale.zerezo.com/git/?p=FAPG;a=blobdiff_plain;f=fapg.c;h=e75235ed9bca7c2ba7cece1fab4dfe73b5208fe4;hp=a3c320ba97a249a18ecda7ac07d5797a7b93e554;hb=eb987a9f4940f5143602e2ef7138550d0263ae40;hpb=d42d5825af7c6b637022eb1bfacf18b2b51bb57c diff --git a/fapg.c b/fapg.c index a3c320b..e75235e 100644 --- a/fapg.c +++ b/fapg.c @@ -1,5 +1,5 @@ /* - * FAPG version 0.22 + * FAPG version 0.30 * * FAPG means Fast Audio Playlist Generator. * It is a tool to generate list of audio files (Wav, MP3, Ogg, etc) @@ -32,9 +32,11 @@ #include #include #include +#include #include #include #include +#include "genres.h" #define MP3_BASE 1024 #define OGG_BASE 1024*10 @@ -42,6 +44,7 @@ int debug=0; int format=0; /* 0 = m3u ; 1 = pls ; 2 = html */ +char *genrelist=NULL; unsigned char *prefix=""; int recursive=0; int separator='/'; @@ -54,28 +57,32 @@ int counter=0; unsigned char artist[1024]; unsigned char title[1024]; +unsigned char genrebuf[1024]; +unsigned char genre=0; int duration; unsigned char unix2dos[256]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,70,35,36,37,38,39,40,41,82,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,84,59,36,61,65,71,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,36,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,36,125,126,127,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,131,225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187,166,166,166,166,166,193,194,192,169,166,166,43,43,162,165,43,43,45,45,43,45,43,227,195,43,43,45,45,166,45,43,164,240,208,202,203,200,105,205,206,207,43,43,166,220,166,204,175,211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180,173,177,61,190,182,167,247,184,176,168,183,185,179,178,166,160}; void usage() { - fprintf(stderr,"Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n"); + fprintf(stderr,"Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-g|--genre=#:#:...] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-x|--exclude=#:#:...] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n"); exit(1); } void parse_options(int argc,char **argv) { - static char const short_options[]="bdf:o:p:rw"; + static char const short_options[]="bdf:g:o:p:rwx:"; static struct option long_options[]= { {"backslash",no_argument,NULL,'b'}, {"debug",no_argument,NULL,'d'}, {"format",required_argument,NULL,'f'}, + {"genre",required_argument,NULL,'g'}, {"output",required_argument,NULL,'o'}, {"prefix",required_argument,NULL,'p'}, {"recursive",no_argument,NULL,'r'}, - {"windows",no_argument,NULL,'w'} + {"windows",no_argument,NULL,'w'}, + {"exclude",required_argument,NULL,'x'} }; int c; int option_index=0; @@ -95,6 +102,20 @@ void parse_options(int argc,char **argv) if (strcmp(optarg,"html")==0) format=2; else usage(); break; + case 'g': + if (genrelist==NULL) genrelist=calloc(257,sizeof(char)); /* allow multiple includes/excludes */ + if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); } + else + { + int n=0; + while (n> genrelist entry activting : %d\n",atoi(&optarg[n])); + genrelist[atoi(&optarg[n])]=1; + while (isdigit(optarg[n++])); + } + } + break; case 'o': close(1); if (fopen(optarg,"w")==NULL) { fprintf(stderr,"Error >> unable to open output file : %s\n",optarg); exit(2); } @@ -110,10 +131,39 @@ void parse_options(int argc,char **argv) windows=1; eol="\r\n"; break; + case 'x': + if (genrelist==NULL) /* allow multiple includes/excludes - not recommended (confusing) but possible */ + { + int n=0; + genrelist=calloc(257,sizeof(char)); + while (n<256) genrelist[n++]=1; + } + if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); } + else + { + int n=0; + while (n> genrelist entry activting : %d\n",atoi(&optarg[n])); + genrelist[atoi(&optarg[n])]=0; + while (isdigit(optarg[n++])); + } + } + break; default: usage(); } } + if (genrelist==NULL) + { + genrelist=calloc(257,sizeof(char)); + if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); } + else + { + int n=0; + while (n<256) genrelist[n++]=1; + } + } } void parse_mp3(unsigned char *file) @@ -129,6 +179,8 @@ void parse_mp3(unsigned char *file) unsigned char *c; int lus; + genre=0; + genrebuf[0]=0; if (debug) fprintf(stderr,"Debug >> parsing mp3 : %s\n",file); /* read header */ @@ -172,6 +224,13 @@ void parse_mp3(unsigned char *file) strncpy(artist,c+7,size-1); artist[size-1]='\0'; } + if (strncmp(c,"TCO",3)==0) + { + /* strncpy(genrebuf,c+7,size-1);*/ + /* genrebuf[size-1]='\0'; */ + /* genre=atoi(&genrebuf[1]); */ + genre=atoi(c+8); + } c+=size+6; } if (version==3 || version==4) while (cartist && *c==' ') *(c--)='\0'; + /* strncpy(album,buffer+65,30); */ + /* strncpy(year,buffer+97,4); */ + /* strncpy(comment,buffer+101,30); */ + /* strncpy(genrebuf,buffer+127,1); genre[1]=0; */ + genre=buffer[127]; } } @@ -281,6 +352,23 @@ void parse_ogg(unsigned char *file) artist[size-7]='\0'; c+=size; } + if (strncasecmp(c,"GENRE=",6)==0) + { + static int i=0; + size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24); + strncpy(genrebuf,c+6,size-6); + genrebuf[size-6]='\0'; + c+=size; + for(i=0;i> parsing mpc : %s\n",file); + + /* read header */ + if ((fic=fopen(file,"r"))==NULL) { fprintf(stderr,"Warning >> can't open file : %s\n",file); return; } + lus=fread(buffer,1,12,fic); + + /* try Musepack */ + if (buffer[0]!='M' && buffer[1]!='P' && buffer[2]!='+') + { + fprintf(stderr,"Warning >> not a Musepack header : %s\n",file); + return; + } + + /* only version 7 */ + if (buffer[3]!=7) + { + fprintf(stderr,"Warning >> only Musepack SV7 supported : %s\n",file); + return; + } + + /* duration */ + c=buffer+4; + frame_count=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24); + c+=5; + duration=frame_count*1152/sample_rates[*c&3]; + + /* try APETAGEX footer */ + fseek(fic,-32,SEEK_END); + lus=fread(buffer,1,32,fic); + if (lus==32 && strncmp(buffer,"APETAGEX",8)==0) + { + c=buffer+12; + size=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24); + size+=32; + c+=4; + items=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24); + fseek(fic,-size,SEEK_END); + lus=fread(buffer,1,size,fic); + if (lus==size && strncmp(buffer,"APETAGEX",8)==0) + { + c=buffer+32; + while (items--) + { + size=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24); + c+=8; + if (strcasecmp(c,"TITLE")==0) + { + strncpy(title,c+6,size); + title[size]='\0'; + } + if (strcasecmp(c,"ARTIST")==0) + { + strncpy(artist,c+7,size); + artist[size]='\0'; + } + if (strcasecmp(c,"GENRE")==0) + { + for(i=0;i%s%s%s%s%sPlaylist generated by FAPG 0.22%s%s%s%s%s%s%s

Playlist

%s%s%s%s",eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol); + printf("%s%s%s%s%sPlaylist generated by FAPG 0.30%s%s%s%s%s%s%s

Playlist

%s%s
EntryArtistTitleLength
%s%s",eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol,eol); break; } for (;optind%s%s

Playlist generated by FAPG 0.22

%s%s%s%s",eol,eol,eol,eol,eol,eol); + printf("
EntryArtistTitleLength
%s%s

Playlist generated by FAPG 0.30

%s%s%s%s",eol,eol,eol,eol,eol,eol); break; } + if (genrelist) free(genrelist); exit(0); }