From: Antoine Jacquet Date: Sat, 4 Oct 2003 22:00:00 +0000 (+0200) Subject: version 0.1 X-Git-Tag: v0.1 X-Git-Url: http://royale.zerezo.com/git/?p=FAPG;a=commitdiff_plain;h=b22241ce33d982f4f45b415f60a341939a26e694 version 0.1 * initial release --- diff --git a/Makefile b/Makefile index 0b26a2d..7dbdd60 100755 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ PRE = /usr/local BIN = $(PRE)/bin -PIX = $(PRE)/share/irssistats/pix -DOC = $(PRE)/doc/irssistats -MAN = $(PRE)/man/man1 +DOC = $(PRE)/doc/fapg fapg:fapg.c gcc -o fapg fapg.c @@ -11,12 +9,10 @@ clean: rm -f fapg install:fapg - mkdir -p $(BIN) $(PIX) $(DOC) $(MAN) + mkdir -p $(BIN) $(DOC) cp -f fapg $(BIN) cp -f COPYING README $(DOC) - cp -f fapg.1 $(MAN) uninstall: rm -f $(BIN)/fapg rm -rf $(DOC) - rm -f $(MAN)/fapg.1 diff --git a/README b/README index ca5ce57..4913345 100755 --- a/README +++ b/README @@ -1,13 +1,23 @@ -FAPG 0.0 (Fast Audio Playlist Generator) +FAPG 0.1 (Fast Audio Playlist Generator) site: http://royale.zerezo.com/fapg/ mail: royale@zerezo.com -This is a pre-released version for testing purpose only ! +install: +make +make install -TODO : - - fapg.css - - define best "size" for MAX constant... - - XML export ? format (DTD) ? - - SQL export ? INSERT INTO playlist VALUES (counter,artist,title,time) ? - - TXT export ? format ? - - support MP3 specials headers (extended & unsynchronisation)... \ No newline at end of file +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 ...] +- backslash : replace the '/' with '\' in Unix path. +- debug : display useful messages if the program fails ;) +- format : choose which format of playlist you want to generate (default is m3u). +- output : choose the name of the playlist file to generate (default behavior is to display on standart output). +- prefix : replace the Unix path with another string (useful to give a Samba path for example). +- recursive : recursively read the subdirectories. +- windows : replace all Unix characters with Windows characters... + +links : +http://geek.scorpiorising.ca/scripts.html +http://id3lib.sourceforge.net/ +http://id3.org/ +http://www.xiph.org/ogg/vorbis/docs.html \ No newline at end of file diff --git a/fapg.c b/fapg.c index eaa8ac3..4dc2cc1 100755 --- a/fapg.c +++ b/fapg.c @@ -1,5 +1,5 @@ /* - * FAPG 0.0 released under GPL + * FAPG 0.1 released under GPL * http://royale.zerezo.com/fapg/ */ @@ -7,9 +7,12 @@ #include #include #include +#include #include #include #include +#include +#include #define MAX 10240 @@ -26,35 +29,40 @@ int counter=0; unsigned char artist[1024]; unsigned char title[1024]; -int time; +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 [-backslash] [-debug] [-format=m3u|pls|html] [-output=/path/to/file.m3u] [-prefix=/the/prefix] [-recursive] [-windows] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n"); + 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"); exit(1); } void parse_options(int argc,char **argv) { + static char const short_options[]="bdf:o:p:rw"; static struct option long_options[]= { - {"backslash",no_argument,&separator,'\\'}, - {"debug",no_argument,&debug,1}, - {"format",required_argument,0,'f'}, - {"output",required_argument,0,'o'}, - {"prefix",required_argument,0,'p'}, - {"recursive",no_argument,&recursive,1}, - {"windows",no_argument,&windows,1} + {"backslash",no_argument,NULL,'b'}, + {"debug",no_argument,NULL,'d'}, + {"format",required_argument,NULL,'f'}, + {"output",required_argument,NULL,'o'}, + {"prefix",required_argument,NULL,'p'}, + {"recursive",no_argument,NULL,'r'}, + {"windows",no_argument,NULL,'w'} }; int c; int option_index=0; - while ((c=getopt_long_only(argc,argv,"",long_options,&option_index))!=-1) + while ((c=getopt_long(argc,argv,short_options,long_options,&option_index))!=-1) { switch(c) { - case 0: + case 'b': + separator='\\'; + break; + case 'd': + debug=1; break; case 'f': if (strcmp(optarg,"m3u")==0) format=0; else @@ -70,6 +78,12 @@ void parse_options(int argc,char **argv) prefix=malloc(strlen(optarg)+1); strcpy(prefix,optarg); break; + case 'r': + recursive=1; + break; + case 'w': + windows=1; + break; default: usage(); } @@ -110,7 +124,7 @@ void parse_mp3(unsigned char *file) size=(*c<<24)+(*(c+1)<<16)+(*(c+2)<<8)+(*(c+3)); if (size>lus) size=lus; c+=4; - if (version==2) while (c> parsing directory : %s\n",path); - if ((dirp=opendir(path))==NULL) { fprintf(stderr,"Warning >> can't open directory : %s\n",path); return; } - while ((dp=readdir(dirp))!=NULL) + if ((n=scandir(path,&namelist,0,alphasort))<0) { fprintf(stderr,"Warning >> can't open directory : %s\n",path); return; } + for (i=0;id_name); - if (recursive && dp->d_type & DT_DIR && strcmp(dp->d_name,".")!=0 && strcmp(dp->d_name,"..")!=0) - { - parse_directory(newpath); - } - if (dp->d_type & DT_REG) + sprintf(newpath,"%s/%s",path,namelist[i]->d_name); + if (stat(newpath,&infos)!=0) { fprintf(stderr,"Warning >> can't stat file : %s\n",newpath); continue; } + if (recursive && S_ISDIR(infos.st_mode) && strcmp(namelist[i]->d_name,".")!=0 && strcmp(namelist[i]->d_name,"..")!=0) parse_directory(newpath); + if (S_ISREG(infos.st_mode)) { unsigned char ext[5]; - int i; - for (i=0;i<5;i++) ext[i]=tolower(dp->d_name[strlen(dp->d_name)-4+i]); + int j; + for (j=0;j<5;j++) ext[j]=tolower(namelist[i]->d_name[strlen(namelist[i]->d_name)-4+j]); artist[0]='\0'; title[0]='\0'; - time=-2; - if (strcmp(".mp3",ext)==0) { time=-1; parse_mp3(newpath); } - if (strcmp(".ogg",ext)==0) { time=-1; parse_ogg(newpath); } - if (strcmp(".wav",ext)==0) { time=-1; /* parse_wav(newpath); */ } + duration=-2; + if (strcmp(".mp3",ext)==0) { duration=-1; parse_mp3(newpath); } + if (strcmp(".ogg",ext)==0) { duration=-1; parse_ogg(newpath); } + if (strcmp(".wav",ext)==0) { duration=-1; /* parse_wav(newpath); */ } - if (time!=-2) /* is it an audio file ? */ + if (duration!=-2) /* is it an audio file ? */ { counter++; switch (format) { case 0: - if (time!=-1) + if (duration!=-1) { - printf("#EXTINF:%d,",time); + printf("#EXTINF:%d,",duration); if (strlen(artist)==0 && strlen(title)==0) print_faketitle(); else printf("%s - %s",artist,title); putchar('\n'); @@ -319,18 +332,19 @@ void parse_directory(unsigned char *path) if (strlen(artist)==0 && strlen(title)==0) print_faketitle(); else printf("%s - %s",artist,title); putchar('\n'); - if (time!=-1) printf("Length%d=%d\n",counter,time); + if (duration!=-1) printf("Length%d=%d\n",counter,duration); break; case 2: printf("%d%s%s",counter,artist,title); - if (time==-1) printf("?"); else printf("%d",time); + if (duration==-1) printf("?"); else printf("%d:%s%d",duration/60,duration%60<10?"0":"",duration%60); printf("\n"); break; } } } + free(namelist[i]); } - closedir(dirp); + free(namelist); } int main(int argc,char **argv) @@ -346,7 +360,7 @@ int main(int argc,char **argv) printf("[playlist]\n"); break; case 2: - printf("\n\n\n\n\nPlaylist generated by FAPG 0.0\n\n\n\n\n\n\n

Playlist

\n\n\n\n"); + printf("\n\n\n\n\nPlaylist generated by FAPG 0.1\n\n\n\n\n\n\n

Playlist

\n\n
EntryArtistTitleLength
\n\n"); break; } for (;optind\n\n

Playlist generated by FAPG 0.0

\n\n\n\n"); + printf("
EntryArtistTitleLength
\n\n

Playlist generated by FAPG 0.1

\n\n\n\n"); break; } exit(0);