e75235ed9bca7c2ba7cece1fab4dfe73b5208fe4
[FAPG] / fapg.c
1 /*
2  * FAPG version 0.30
3  *
4  * FAPG means Fast Audio Playlist Generator.
5  * It is a tool to generate list of audio files (Wav, MP3, Ogg, etc)
6  * in various formats (M3U, PLS, HTML, etc).
7  * It is very usefull if you have a large amount of audio files
8  * and you want to quickly and frequently build a playlist.
9  *
10  * Copyright (C) 2003-2004  Antoine Jacquet <royale@zerezo.com>
11  * http://royale.zerezo.com/fapg/
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <getopt.h>
31 #include <dirent.h>
32 #include <sys/stat.h>
33 #include <sys/types.h>
34 #include <string.h>
35 #include <strings.h>
36 #include <limits.h>
37 #include <unistd.h>
38 #include <ctype.h>
39 #include "genres.h"
40
41 #define MP3_BASE 1024
42 #define OGG_BASE 1024*10
43 #define MAX 1024*200 /* 200ko for ID3 with JPEG images in it */
44
45 int debug=0;
46 int format=0; /* 0 = m3u ; 1 = pls ; 2 = html */
47 char *genrelist=NULL;
48 unsigned char *prefix="";
49 int recursive=0;
50 int separator='/';
51 int skip=0;
52 int windows=0;
53 unsigned char *eol="\n";
54 unsigned char buffer[MAX];
55
56 int counter=0;
57
58 unsigned char artist[1024];
59 unsigned char title[1024];
60 unsigned char genrebuf[1024];
61 unsigned char genre=0;
62 int duration;
63
64 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};
65
66 void usage()
67 {
68   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");
69   exit(1);
70 }
71
72 void parse_options(int argc,char **argv)
73 {
74   static char const short_options[]="bdf:g:o:p:rwx:";
75   static struct option long_options[]=
76   {
77     {"backslash",no_argument,NULL,'b'},
78     {"debug",no_argument,NULL,'d'},
79     {"format",required_argument,NULL,'f'},
80     {"genre",required_argument,NULL,'g'},
81     {"output",required_argument,NULL,'o'},
82     {"prefix",required_argument,NULL,'p'},
83     {"recursive",no_argument,NULL,'r'},
84     {"windows",no_argument,NULL,'w'},
85     {"exclude",required_argument,NULL,'x'}
86   };
87   int c;
88   int option_index=0;
89   while ((c=getopt_long(argc,argv,short_options,long_options,&option_index))!=-1)
90   {
91     switch(c)
92     {
93       case 'b':
94         separator='\\';
95         break;
96       case 'd':
97         debug=1;
98         break;
99       case 'f':
100         if (strcmp(optarg,"m3u")==0)  format=0; else
101         if (strcmp(optarg,"pls")==0)  format=1; else
102         if (strcmp(optarg,"html")==0) format=2; else
103         usage();
104         break;
105       case 'g':
106         if (genrelist==NULL) genrelist=calloc(257,sizeof(char)); /* allow multiple includes/excludes */
107         if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); }
108         else
109         {
110           int n=0; 
111           while (n<strlen(optarg))
112           {
113             if (debug) fprintf(stderr,"Debug >> genrelist entry activting : %d\n",atoi(&optarg[n]));
114             genrelist[atoi(&optarg[n])]=1;
115             while (isdigit(optarg[n++]));
116           }
117         }
118         break;
119       case 'o':
120         close(1);
121         if (fopen(optarg,"w")==NULL) { fprintf(stderr,"Error >> unable to open output file : %s\n",optarg); exit(2); }
122         break;
123       case 'p':
124         prefix=malloc(strlen(optarg)+1);
125         strcpy(prefix,optarg);
126         break;
127       case 'r':
128         recursive=1;
129         break;
130       case 'w':
131         windows=1;
132         eol="\r\n";
133         break;
134       case 'x':
135         if (genrelist==NULL) /* allow multiple includes/excludes - not recommended (confusing) but possible */
136         {
137           int n=0; 
138           genrelist=calloc(257,sizeof(char));
139           while (n<256) genrelist[n++]=1;
140         }
141         if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); }
142         else
143         {
144           int n=0; 
145           while (n<strlen(optarg))
146           {
147             if (debug) fprintf(stderr,"Debug >> genrelist entry activting : %d\n",atoi(&optarg[n]));
148             genrelist[atoi(&optarg[n])]=0;
149             while (isdigit(optarg[n++]));
150           }
151         }
152         break;
153       default:
154         usage();
155     }
156   }
157   if (genrelist==NULL)
158   {
159     genrelist=calloc(257,sizeof(char));
160     if (genrelist==NULL) { fprintf(stderr,"Error >> unable to allocate cleared memory\n"); exit(2); }
161     else
162     { 
163       int n=0; 
164       while (n<256) genrelist[n++]=1;
165     }
166   }
167 }
168
169 void parse_mp3(unsigned char *file)
170 {
171   int bitrates[2][3][15]=
172     {{{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448},
173       {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384},
174       {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}},
175      {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256},
176       {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
177       {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}}};
178   FILE *fic;
179   unsigned char *c;
180   int lus;
181
182   genre=0;
183   genrebuf[0]=0;
184   if (debug) fprintf(stderr,"Debug >> parsing mp3 : %s\n",file);
185
186   /* read header */
187   if ((fic=fopen(file,"r"))==NULL) { fprintf(stderr,"Warning >> can't open file : %s\n",file); return; }
188   lus=fread(buffer,1,MP3_BASE,fic);
189   c=buffer;  
190
191   /* try ID3v2 */
192   if (buffer[0]=='I' && buffer[1]=='D' && buffer[2]=='3')
193   {
194     int size;
195     int version;
196     version=*(buffer+3);
197     if (version<2 || version>4)
198       fprintf(stderr,"Warning >> ID3 v2.%d not implemented ! trying anyway : %s\n",version,file);
199     if (*(buffer+5)!=0)
200       fprintf(stderr,"Warning >> specials headers not implemented (%d) ! trying anyway : %s\n",*(buffer+5),file);
201     c=buffer+6;
202     size=(*c<<21)+(*(c+1)<<14)+(*(c+2)<<7)+(*(c+3));
203     /* read more header */
204     if (size+lus>MAX)
205     {
206       lus+=fread(buffer+lus,1,MAX-lus,fic);
207       fprintf(stderr,"Warning >> ID3 header is huge (%d bytes) ! trying anyway : %s\n",size,file);
208     }
209     else
210       lus+=fread(buffer+lus,1,size,fic);
211     if (size>lus) size=lus;
212     c+=4;
213     if (version==2) while (c<buffer+size)
214     {
215       int size=(*(c+3)<<16)+(*(c+4)<<8)+(*(c+5));
216       if (*c==0) break;
217       if (strncmp(c,"TT2",3)==0)
218       {
219         strncpy(title,c+7,size-1);
220         title[size-1]='\0';
221       }
222       if (strncmp(c,"TP1",3)==0)
223       {
224         strncpy(artist,c+7,size-1);
225         artist[size-1]='\0';
226       }
227       if (strncmp(c,"TCO",3)==0)
228       {
229         /* strncpy(genrebuf,c+7,size-1);*/
230         /* genrebuf[size-1]='\0'; */
231         /* genre=atoi(&genrebuf[1]); */
232         genre=atoi(c+8);
233       }
234       c+=size+6;
235     }
236     if (version==3 || version==4) while (c<buffer+size)
237     {
238       int size=(*(c+4)<<24)+(*(c+5)<<16)+(*(c+6)<<8)+(*(c+7));
239       if (*c==0) break;
240       if (strncmp(c,"TIT2",4)==0)
241       {
242         strncpy(title,c+11,size-1);
243         title[size-1]='\0';
244       }
245       if (strncmp(c,"TPE1",4)==0)
246       {
247         strncpy(artist,c+11,size-1);
248         artist[size-1]='\0';
249       }
250       if (strncmp(c,"TCON",4)==0)
251       {
252         /* strncpy(genrebuf,c+11,size-1); */
253         /* genrebuf[size-1]='\0'; */
254         /* genre=atoi(&genrebuf[1]); */
255         genre=atoi(c+12);
256       }
257       c+=size+10;
258     }
259   }
260   
261   while (c<buffer+lus-10)
262   {
263     if (*c==0xFF && (*(c+1)&0xF0)==0xF0)
264     {
265       int version;
266       int lay;
267       int bitrate_index;
268       int bitrate;
269       version=2-(*(c+1)>>3&1);
270       lay=4-(*(c+1)>>1&3);
271       bitrate_index=*(c+2)>>4&0xF;
272       if (version>=1 && version<=2 && lay-1>=0 && lay-1<=2 && bitrate_index>=0 && bitrate_index<=14)
273         bitrate=bitrates[version-1][lay-1][bitrate_index];
274       else
275         bitrate=0;
276       if (bitrate!=0)
277       {
278         fseek(fic,0,SEEK_END);
279         duration=(ftell(fic)+buffer-c)/125/bitrate;
280       }
281       else
282         duration=0;
283       break;
284     }
285     c++;
286   }
287
288   /* try ID3v1 */
289   if (strlen(artist)==0 && strlen(title)==0)
290   {
291     fseek(fic,-128,SEEK_END);
292     lus=fread(buffer,1,128,fic);
293     if (lus==128 && buffer[0]=='T' && buffer[1]=='A' && buffer[2]=='G')
294     {
295       strncpy(title,buffer+3,30);
296       title[30]='\0';
297       c=title+29;
298       while (c>title && *c==' ') *(c--)='\0';
299       strncpy(artist,buffer+33,30);
300       artist[30]='\0';
301       c=artist+29;
302       while (c>artist && *c==' ') *(c--)='\0';
303       /* strncpy(album,buffer+65,30); */
304       /* strncpy(year,buffer+97,4); */
305       /* strncpy(comment,buffer+101,30); */
306       /* strncpy(genrebuf,buffer+127,1); genre[1]=0; */
307       genre=buffer[127];
308     }
309   }
310
311   fclose(fic);
312 }  
313
314 void parse_ogg(unsigned char *file)
315 {
316   FILE *fic;
317   unsigned char *c;
318   int lus;
319   int sample_rate;
320   int samples;
321
322   if (debug) fprintf(stderr,"Debug >> parsing ogg : %s\n",file);
323
324   /* read header */
325   if ((fic=fopen(file,"r"))==NULL) { fprintf(stderr,"Warning >> can't open file : %s\n",file); return; }
326   lus=fread(buffer,1,OGG_BASE,fic);
327
328   /* try Ogg */
329   if (buffer[0]!='O' && buffer[1]!='g' && buffer[2]!='g')
330   {
331     fprintf(stderr,"Warning >> not a Ogg header : %s\n",file);
332     return;
333   }
334   
335   c=buffer+0x28;
336   sample_rate=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
337
338   while (c<buffer+lus-10)
339   {
340     int size;
341     if (strncasecmp(c,"TITLE=",6)==0)
342     {
343       size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24);
344       strncpy(title,c+6,size-6);
345       title[size-6]='\0';
346       c+=size;
347     }
348     if (strncasecmp(c,"ARTIST=",7)==0)
349     {
350       size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24);
351       strncpy(artist,c+7,size-7);
352       artist[size-7]='\0';
353       c+=size;
354     }
355     if (strncasecmp(c,"GENRE=",6)==0)
356     {
357       static int i=0;
358       size=*(c-4)+(*(c-3)<<8)+(*(c-2)<<16)+(*(c-1)<<24);
359       strncpy(genrebuf,c+6,size-6);
360       genrebuf[size-6]='\0';
361       c+=size;
362       for(i=0;i<ID3_NR_OF_V1_GENRES;i++)
363       {
364         if (strcasecmp(ID3_v1_genre_description[i],genrebuf)==0)
365         {
366           genre=i;
367           break;
368         }
369         if (i==ID3_NR_OF_V1_GENRES) genre=0;
370       }
371     }
372     c++;
373   }
374   
375   fseek(fic,-OGG_BASE,SEEK_END);
376   lus=fread(buffer,1,OGG_BASE,fic);
377   c=buffer+lus-1;
378   while (strncmp(c,"OggS",4)!=0 && c>buffer) c--;
379   if (c!=buffer)
380   {
381     c+=6;
382     samples=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
383     duration=samples/sample_rate;
384   }
385   
386   fclose(fic);
387 }
388
389 void parse_mpc(unsigned char *file)
390 {
391   FILE *fic;
392   unsigned char *c;
393   int lus;
394   int sample_rates[4]={44100,48000,37800,32000};
395   int frame_count;
396   int size,items;
397   int i;
398
399   if (debug) fprintf(stderr,"Debug >> parsing mpc : %s\n",file);
400
401   /* read header */
402   if ((fic=fopen(file,"r"))==NULL) { fprintf(stderr,"Warning >> can't open file : %s\n",file); return; }
403   lus=fread(buffer,1,12,fic);
404
405   /* try Musepack */
406   if (buffer[0]!='M' && buffer[1]!='P' && buffer[2]!='+')
407   {
408     fprintf(stderr,"Warning >> not a Musepack header : %s\n",file);
409     return;
410   }
411   
412   /* only version 7 */
413   if (buffer[3]!=7)
414   {
415     fprintf(stderr,"Warning >> only Musepack SV7 supported : %s\n",file);
416     return;
417   }
418   
419   /* duration */
420   c=buffer+4;
421   frame_count=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
422   c+=5;
423   duration=frame_count*1152/sample_rates[*c&3];
424   
425   /* try APETAGEX footer */
426   fseek(fic,-32,SEEK_END);
427   lus=fread(buffer,1,32,fic);
428   if (lus==32 && strncmp(buffer,"APETAGEX",8)==0)
429   {
430     c=buffer+12;
431     size=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
432     size+=32;
433     c+=4;
434     items=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
435     fseek(fic,-size,SEEK_END);
436     lus=fread(buffer,1,size,fic);
437     if (lus==size && strncmp(buffer,"APETAGEX",8)==0)
438     {
439       c=buffer+32;
440       while (items--)
441       {
442         size=(*c)+(*(c+1)<<8)+(*(c+2)<<16)+(*(c+3)<<24);
443         c+=8;
444         if (strcasecmp(c,"TITLE")==0)
445         {
446           strncpy(title,c+6,size);
447           title[size]='\0';
448         }
449         if (strcasecmp(c,"ARTIST")==0)
450         {
451           strncpy(artist,c+7,size);
452           artist[size]='\0';
453         }
454         if (strcasecmp(c,"GENRE")==0)
455         {
456           for(i=0;i<ID3_NR_OF_V1_GENRES;i++)
457           {
458             strncpy(genrebuf,c+6,size);
459             genrebuf[size]='\0';
460             if (strcasecmp(ID3_v1_genre_description[i],genrebuf)==0)
461             {
462               genre=i;
463               break;
464             }
465             if (i==ID3_NR_OF_V1_GENRES) genre=0;
466           }
467         }
468         c+=strlen(c)+1+size;
469       }
470     }
471   }
472
473   fclose(fic);
474 }
475
476 void parse_directory(unsigned char *path)
477 {
478   int i,n;
479   struct dirent **namelist;
480   unsigned char newpath[PATH_MAX];
481   unsigned char *c;
482   struct stat infos;
483
484   void print_faketitle()
485   {
486     c=newpath+strlen(newpath);
487     while (c>newpath && *c!='/') c--;
488     while (c<newpath+strlen(newpath)-5)
489     {
490       c++;
491       if (*c=='_') putchar(' '); else if (windows) putchar(unix2dos[*c]); else putchar(*c);
492     }
493   }
494   
495   void print_path()
496   {
497     printf(prefix);
498     for (c=newpath+skip;*c!='\0';c++) if (*c=='/') putchar(separator); else if (windows) putchar(unix2dos[*c]); else putchar(*c);
499   }
500
501   if (debug) fprintf(stderr,"Debug >> parsing directory : %s\n",path);
502   if ((n=scandir(path,&namelist,0,alphasort))<0) { fprintf(stderr,"Warning >> can't open directory : %s\n",path); return; }
503   for (i=0;i<n;i++)
504   {
505     sprintf(newpath,"%s/%s",path,namelist[i]->d_name);
506     if (stat(newpath,&infos)!=0) { fprintf(stderr,"Warning >> can't stat file : %s\n",newpath); continue; }
507     if (recursive && S_ISDIR(infos.st_mode) && strcmp(namelist[i]->d_name,".")!=0 && strcmp(namelist[i]->d_name,"..")!=0) parse_directory(newpath);
508     if (S_ISREG(infos.st_mode))
509     {
510       unsigned char ext[5];
511       int j;
512       for (j=0;j<5;j++) ext[j]=tolower(namelist[i]->d_name[strlen(namelist[i]->d_name)-4+j]);
513       artist[0]='\0';
514       title[0]='\0';
515       duration=-2;
516       if (strcmp(".mp2",ext)==0) { duration=-1; parse_mp3(newpath); }
517       if (strcmp(".mp3",ext)==0) { duration=-1; parse_mp3(newpath); }
518       if (strcmp(".mpc",ext)==0) { duration=-1; parse_mpc(newpath); }
519       if (strcmp(".mp+",ext)==0) { duration=-1; parse_mpc(newpath); }
520       if (strcmp(".ogg",ext)==0) { duration=-1; parse_ogg(newpath); }
521       if (strcmp(".wav",ext)==0) { duration=-1; /* parse_wav(newpath); */ }
522       
523       if (duration!=-2 && genrelist[genre]) /* is it an audio file ? */
524       {
525         counter++;
526         switch (format)
527         {
528           case 0:
529             if (duration!=-1)
530             {
531               printf("#EXTINF:%d,",duration);
532               if (strlen(artist)==0 && strlen(title)==0) print_faketitle();
533               else printf("%s - %s",artist,title);
534               printf("%s",eol);
535             }
536             print_path();
537             printf("%s",eol);
538             break;
539           case 1:
540             printf("File%d=",counter);
541             print_path();
542             printf("%s",eol);
543             printf("Title%d=",counter);
544             if (strlen(artist)==0 && strlen(title)==0) print_faketitle();
545             else printf("%s - %s",artist,title);
546             printf("%s",eol);
547             if (duration!=-1) printf("Length%d=%d%s",counter,duration,eol);
548             break;
549           case 2:
550             printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>",counter,artist,title);
551             if (duration==-1) printf("?"); else printf("%d:%s%d",duration/60,duration%60<10?"0":"",duration%60);
552             printf("</td></tr>%s",eol);
553             break;
554         }
555       }
556     }
557     free(namelist[i]);
558   }
559   free(namelist);
560 }
561
562 int main(int argc,char **argv)
563 {
564   parse_options(argc,argv);
565   if (optind==argc) usage();
566   switch (format)
567   {
568     case 0:
569       printf("#EXTM3U%s",eol);
570       break;
571     case 1:
572       printf("[playlist]%s",eol);
573       break;
574     case 2:
575       printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">%s%s<html>%s%s<head>%s<title>Playlist generated by FAPG 0.30</title>%s<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />%s<style type=\"text/css\">%s<!--%s%sbody,td,tr {%s font-family: Verdana, Arial, Helvetica, sans-serif;%s  font-size: 12px;%s  color: #000000;%s}%s%sbody {%s  background: #ffffff;%s}%s%sth {%s  text-align: center;%s  background: #ffcccc;%s  padding-left: 15px;%s  padding-right: 15px;%s  border: 1px #dd8888 solid;%s}%s%std {%s  text-align: center;%s  background: #eeeeee;%s  padding-left: 15px;%s  padding-right: 15px;%s  border: 1px #cccccc solid;%s}%s%sh1 {%s  font-size: 25px;%s}%s%sp {%s  font-size: 10px;%s}%s%sa {%s  color: #993333;%s  text-decoration: none;%s}%s%sa:hover {%s text-decoration: underline;%s}%s%s-->%s</style>%s</head>%s%s<body>%s%s<h1>Playlist</h1>%s%s<table>%s<tr><th>Entry</th><th>Artist</th><th>Title</th><th>Length</th></tr>%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);
576       break;
577   }
578   for (;optind<argc;optind++)
579   {
580     if (strlen(prefix)!=0) skip=strlen(argv[optind]);
581     parse_directory(argv[optind]);
582   }
583   switch(format)
584   {
585     case 1:
586       printf("NumberOfEntries=%d%sVersion=2%s",counter,eol,eol);
587       break;
588     case 2:
589       printf("</table>%s%s<p>Playlist generated by <a href=\"http://royale.zerezo.com/fapg/\">FAPG 0.30</a></p>%s%s</body>%s%s</html>",eol,eol,eol,eol,eol,eol);
590       break;
591   }
592   if (genrelist) free(genrelist);
593   exit(0);
594 }