From eb987a9f4940f5143602e2ef7138550d0263ae40 Mon Sep 17 00:00:00 2001 From: Antoine Jacquet Date: Tue, 12 Oct 2004 00:00:00 +0200 Subject: [PATCH] version 0.30 * selection by genre was added (thank you Andreas Neuper) * MP2 files are parsed for mp3 headers (thank you Andreas Neuper) * added support for Musepack files with APE tag --- CHANGELOG | 7 +- Makefile | 4 +- README | 6 +- fapg.1 | 21 ++++-- fapg.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++--- genres.h | 158 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 373 insertions(+), 18 deletions(-) create mode 100644 genres.h diff --git a/CHANGELOG b/CHANGELOG index c9a42c4..ff59438 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,10 @@ Change log file for FAPG +version 0.30 (2004-10-12) + * selection by genre was added (thank you Andreas Neuper) + * MP2 files are parsed for mp3 headers (thank you Andreas Neuper) + * added support for Musepack files with APE tag + version 0.22 (2004-06-02) * case-insensitive field names in Ogg Vorbis headers (patch by Jon Burgess) @@ -15,4 +20,4 @@ version 0.1 (2003-10-05) * initial release version 0.0 (2003-10-01) - * beta pre-release \ No newline at end of file + * beta pre-release diff --git a/Makefile b/Makefile index 2949454..990ae9c 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ BIN = $(PRE)/bin DOC = $(PRE)/share/doc/fapg MAN = $(PRE)/share/man/man1 -fapg:fapg.c - gcc -o fapg fapg.c +fapg:fapg.c genres.h + gcc -Wall -o fapg fapg.c clean: rm -f fapg diff --git a/README b/README index 9ed8009..7904dd2 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -FAPG 0.22 (Fast Audio Playlist Generator) +FAPG 0.30 (Fast Audio Playlist Generator) site: http://royale.zerezo.com/fapg/ mail: royale@zerezo.com @@ -7,14 +7,16 @@ make make install 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 ...] +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 ...] - 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). +- genre : choose which genres will be included in the generated playlist (default is all). - 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... +- exclude : choose which genres will be excluded in the generated playlist (default is none). links : http://geek.scorpiorising.ca/scripts.html diff --git a/fapg.1 b/fapg.1 index 096ddcf..e909bdb 100644 --- a/fapg.1 +++ b/fapg.1 @@ -7,11 +7,15 @@ fapg \- Fast Audio Playlist Generator .SH SYNOPSIS -.B fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-o|--output= +.B fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html] [-g|--genre +.I #:#:... +.B ] [-o|--output= .I /path/to/file.m3u .B ] [-p|--prefix= .I /the/prefix -.B ] [-r|--recursive] [-w|--windows] +.B ] [-r|--recursive] [-w|--windows] [-x|--exclude +.I #:#:... +.B ] .I /path/to/mp3/dir1 .B [ .I /path/to/mp3/dir2 @@ -19,7 +23,7 @@ fapg \- Fast Audio Playlist Generator .SH DESCRIPTION .B fapg -is a tool to generate list of audio files (Wav, MP3, Ogg, etc) in various +is a tool to generate list of audio files (Wav, MP2, MP3, Ogg, etc) in various formats (M3U, PLS, HTML, etc). It is very useful if you have a large amount of audio files and you want to quickly and frequently build a playlist. .P @@ -36,6 +40,8 @@ Replace the '/' with '\' in Unix path. Display useful messages if the program fails ;) .IP -f|--format=m3u|pls|html Choose which format of playlist you want to generate (default is m3u). +.IP -g|--genre=#:#:... +Choose which genres (numerical values only) will be included in the generated playlist (default is all). .IP -o|--output=/path/to/file.m3u Choose the name of the playlist file to generate (default behavior is to display on standard output). @@ -46,6 +52,8 @@ for example). Recursively read the subdirectories. .IP -w|--windows Replace all Unix characters with Windows characters. +.IP -x|--exclude=#:#:... +Choose which genres (numerical values only) will be excluded in the generated playlist (default is none). .SH EXAMPLES Generate a PLS playlist for an album: @@ -56,13 +64,16 @@ audio files for Windows powered computers using Winamp. The directory on the server containing the files is .I /samba/mp3 and is visible on the Windows network as -.I \\\\\\\server\\\mp3 +.I \\\\\\\\server\\\\mp3 : -.B fapg --backslash --output=/samba/mp3/list.m3u --prefix='\\server\mp3\' --recursive --windows /samba/mp3 +.B fapg --backslash --output=/samba/mp3/list.m3u --prefix='\\\\\\\\server\\\\mp3\\\\' --recursive --windows /samba/mp3 An HTML playlist for an album: .B fapg --output=fapg.html ~/path/to/album +A playlist that contains all your classical tracks may receive the genres to include (or exclude) in one or multiple portions +.B fapg --genre=32:105 --genre=106:104:103 /path/to/all/music + .SH AUTHOR Antoine Jacquet , http://royale.zerezo.com/fapg/. 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); } diff --git a/genres.h b/genres.h new file mode 100644 index 0000000..9a5600b --- /dev/null +++ b/genres.h @@ -0,0 +1,158 @@ +/* copied from id3/globals.h */ + +#define ID3_NR_OF_V1_GENRES 148 + +static const char *ID3_v1_genre_description[ID3_NR_OF_V1_GENRES] = +{ + "Blues", //0 + "Classic Rock", //1 + "Country", //2 + "Dance", //3 + "Disco", //4 + "Funk", //5 + "Grunge", //6 + "Hip-Hop", //7 + "Jazz", //8 + "Metal", //9 + "New Age", //10 + "Oldies", //11 + "Other", //12 + "Pop", //13 + "R&B", //14 + "Rap", //15 + "Reggae", //16 + "Rock", //17 + "Techno", //18 + "Industrial", //19 + "Alternative", //20 + "Ska", //21 + "Death Metal", //22 + "Pranks", //23 + "Soundtrack", //24 + "Euro-Techno", //25 + "Ambient", //26 + "Trip-Hop", //27 + "Vocal", //28 + "Jazz+Funk", //29 + "Fusion", //30 + "Trance", //31 + "Classical", //32 + "Instrumental", //33 + "Acid", //34 + "House", //35 + "Game", //36 + "Sound Clip", //37 + "Gospel", //38 + "Noise", //39 + "AlternRock", //40 + "Bass", //41 + "Soul", //42 + "Punk", //43 + "Space", //44 + "Meditative", //45 + "Instrumental Pop", //46 + "Instrumental Rock", //47 + "Ethnic", //48 + "Gothic", //49 + "Darkwave", //50 + "Techno-Industrial", //51 + "Electronic", //52 + "Pop-Folk", //53 + "Eurodance", //54 + "Dream", //55 + "Southern Rock", //56 + "Comedy", //57 + "Cult", //58 + "Gangsta", //59 + "Top 40", //60 + "Christian Rap", //61 + "Pop/Funk", //62 + "Jungle", //63 + "Native American", //64 + "Cabaret", //65 + "New Wave", //66 + "Psychadelic", //67 + "Rave", //68 + "Showtunes", //69 + "Trailer", //70 + "Lo-Fi", //71 + "Tribal", //72 + "Acid Punk", //73 + "Acid Jazz", //74 + "Polka", //75 + "Retro", //76 + "Musical", //77 + "Rock & Roll", //78 + "Hard Rock", //79 +// following are winamp extentions + "Folk", //80 + "Folk-Rock", //81 + "National Folk", //82 + "Swing", //83 + "Fast Fusion", //84 + "Bebob", //85 + "Latin", //86 + "Revival", //87 + "Celtic", //88 + "Bluegrass", //89 + "Avantgarde", //90 + "Gothic Rock", //91 + "Progressive Rock", //92 + "Psychedelic Rock", //93 + "Symphonic Rock", //94 + "Slow Rock", //95 + "Big Band", //96 + "Chorus", //97 + "Easy Listening", //98 + "Acoustic", //99 + "Humour", //100 + "Speech", //101 + "Chanson", //102 + "Opera", //103 + "Chamber Music", //104 + "Sonata", //105 + "Symphony", //106 + "Booty Bass", //107 + "Primus", //108 + "Porn Groove", //109 + "Satire", //110 + "Slow Jam", //111 + "Club", //112 + "Tango", //113 + "Samba", //114 + "Folklore", //115 + "Ballad", //116 + "Power Ballad", //117 + "Rhythmic Soul", //118 + "Freestyle", //119 + "Duet", //120 + "Punk Rock", //121 + "Drum Solo", //122 + "A capella", //123 + "Euro-House", //124 + "Dance Hall", //125 + "Goa", //126 + "Drum & Bass", //127 + "Club-House", //128 + "Hardcore", //129 + "Terror", //130 + "Indie", //131 + "Britpop", //132 + "Negerpunk", //133 + "Polsk Punk", //134 + "Beat", //135 + "Christian Gangsta Rap", //136 + "Heavy Metal", //137 + "Black Metal", //138 + "Crossover", //139 + "Contemporary Christian",//140 + "Christian Rock ", //141 + "Merengue", //142 + "Salsa", //143 + "Trash Metal", //144 + "Anime", //145 + "JPop", //146 + "Synthpop" //147 +}; + +#define ID3_V1GENRE2DESCRIPTION(x) (x < ID3_NR_OF_V1_GENRES && x >= 0) ? ID3_v1_genre_description[x] : NULL -- 2.20.1