From 57a557c838aebd9b7fbd1344f6fcb86b7d5da7fd Mon Sep 17 00:00:00 2001 From: Antoine Jacquet Date: Wed, 7 Mar 2007 00:00:00 +0100 Subject: [PATCH] version 0.37 * added a --stdin option to act as a filter (read filenames and directories from input) * trim spaces in artist/title when guessing from filename * restore --backslash option behavior --- CHANGELOG | 9 ++++-- Makefile | 2 +- README | 7 +++-- fapg.1 | 4 +++ fapg.c | 84 ++++++++++++++++++++++++++++++++++++++++++------------- 5 files changed, 80 insertions(+), 26 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index af891f2..315463f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,13 @@ Change log file for FAPG +version 0.37 (2007-03-07) + * added a --stdin option to act as a filter (read filenames and directories from input) + * trim spaces in artist/title when guessing from filename + * restore --backslash option behavior + version 0.36 (2007-01-17) (by Hank Barta) - * Added .pla output (to work with Sansa e200 series player) - * Fix segmentation fault with backslash option (patch by Antoine Jacquet) + * added .pla output (to work with Sansa e200 series player) + * fix segmentation fault with backslash option (patch by Antoine Jacquet) version 0.35 (2006-02-08) (by Andreas Neuper) * BUG fix: no more ampersand in RSS feeds are passed diff --git a/Makefile b/Makefile index 6e8000f..b1c192a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PRE = /usr/local BIN = $(PRE)/bin DOC = $(PRE)/share/doc/fapg MAN = $(PRE)/share/man/man1 -CFLAGS=-Wall -g2 -funsigned-char +CFLAGS=-g2 -funsigned-char fapg: fapg.c diff --git a/README b/README index 9a2ec11..f180f76 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -FAPG 0.36 (Fast Audio Playlist Generator) +FAPG 0.37 (Fast Audio Playlist Generator) site: http://royale.zerezo.com/fapg/ mail: royale@zerezo.com @@ -7,7 +7,7 @@ make make install usage: -fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss|pla] [-g|--genre=#:#:...] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-x|--exclude=#:#:...] [-c|--command=] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...] +fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss|pla] [-g|--genre=#:#:...] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-x|--exclude=#:#:...] [-c|--command=] [-s|--stdin] /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). @@ -17,7 +17,8 @@ fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss|pla] [-g|--genr - 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). -- command : external binary or script that produces additional fields for RSS feeds (slow) +- command : external binary or script that produces additional fields for RSS feeds (slow). +- stdin : read filenames and/or directories from standard input instead of command line. links : http://geek.scorpiorising.ca/scripts.html diff --git a/fapg.1 b/fapg.1 index 88b48d5..955eb52 100644 --- a/fapg.1 +++ b/fapg.1 @@ -50,6 +50,10 @@ Recursively read the subdirectories. 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). +.IP -c|--command= +External binary or script that produces additional fields for RSS feeds (slow). +.IP -s|--stdin +Read filenames and/or directories from standard input instead of command line. .SH EXAMPLES Generate a PLS playlist for an album: diff --git a/fapg.c b/fapg.c index 0ec3835..ea50917 100644 --- a/fapg.c +++ b/fapg.c @@ -38,7 +38,7 @@ #include #include "genres.h" -#define VERSION "0.36" +#define VERSION "0.37" #define MP3_BASE 1024 #define OGG_BASE 1024*10 #define MAX 1024*200 /* 200ko for ID3 with JPEG images in it */ @@ -53,6 +53,7 @@ unsigned char *hostname = "fritzserver.de"; // unsigned char *referal="/usr/local/bin/fapg-rss.sh"; unsigned char *referal = NULL; //int windows=0; +int fromstdin = 0; int recursive = 0; int avoidhlinked = 0; int separator = '/'; @@ -217,7 +218,7 @@ unsigned char *iso2web[256] = { void usage() { fprintf(stderr, - "Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss|pla] [-g|--genre=#:#:...] [-n|--nohardlink] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-c|--command=] [-x|--exclude=#:#:...] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n"); + "Usage >> fapg [-b|--backslash] [-d|--debug] [-f|--format=m3u|pls|html|rss|pla] [-g|--genre=#:#:...] [-n|--nohardlink] [-o|--output=/path/to/file.m3u] [-p|--prefix=/the/prefix] [-r|--recursive] [-w|--windows] [-c|--command=] [-x|--exclude=#:#:...] [-s|--stdin] /path/to/mp3/dir1 [/path/to/mp3/dir2 ...]\n"); exit(1); } @@ -241,7 +242,7 @@ void mywebputstr(const char *c) void myplaputstr(const char *c) { while(*c != 0) { - if( *c == '/') + if(*c == '/') myplaputchar('\\'); /* translate slash to backslash */ else myplaputchar(*c); @@ -255,7 +256,10 @@ void myplaputstr(const char *c) void myputstr(const char *c) { while(*c != 0) { - myputchar(*c); + if(*c == '/') + putchar(separator); + else + myputchar(*c); c++; /* remove multiple slashes "//" when parsing a directory ending with a "/" */ while(*c == '/' && c[1] == '/') @@ -263,6 +267,24 @@ void myputstr(const char *c) } } +/* remove spaces at beginning and end of string */ +void trim(char *c) +{ + char *p; + /* remove spaces at beginning ... */ + while(*c == ' ') { + p = c; + while(*p != '\0') { + *p = *(p + 1); + p++; + } + } + /* ... and end of string */ + p = c + strlen(c); + while(--p > c && *p == ' ') + *p = '\0'; +} + void print_webpath(const char *path) { const char *c = path; @@ -356,10 +378,10 @@ void reference(const char *title) void parse_options(int argc, char **argv) { - static char const short_options[] = "c:bdf:g:lo:np:ruwx:"; + static char const short_options[] = "bc:df:g:lo:np:rsuwx:"; static struct option long_options[] = { {"backslash", no_argument, NULL, 'b'}, - {"command", required_argument, NULL, 'b'}, + {"command", required_argument, NULL, 'c'}, {"debug", no_argument, NULL, 'd'}, {"format", required_argument, NULL, 'f'}, {"genre", required_argument, NULL, 'g'}, @@ -367,6 +389,7 @@ void parse_options(int argc, char **argv) {"output", required_argument, NULL, 'o'}, {"prefix", required_argument, NULL, 'p'}, {"recursive", no_argument, NULL, 'r'}, + {"stdin", no_argument, NULL, 's'}, {"windows", no_argument, NULL, 'w'}, {"exclude", required_argument, NULL, 'x'} }; @@ -482,6 +505,9 @@ void parse_options(int argc, char **argv) } } break; + case 's': + fromstdin = 1; + break; default: usage(); } @@ -934,12 +960,13 @@ void parse_file(unsigned char *newpath) duration = -1; /* parse_wav(newpath); */ encoding = WAVENC; } - /* faketitle() */ + /* guesstitle() */ if((strlen(artist) == 0) && (strlen(title) == 0)) { // there are no tag infos read // use file name to state substitute it char *c = strrchr(newpath, separator); - if (c == NULL) c = newpath; + if(c == NULL) + c = newpath; strcpy(artist, ++c); // arbitrarily use the first '-' // to separate artist and title @@ -960,16 +987,21 @@ void parse_file(unsigned char *newpath) *c = ' '; for(c = title; (c = strchr(c, '_')) != NULL; c++) *c = ' '; + // trim spaces + trim(artist); + trim(title); } - /* faketitle() end */ + /* guesstitle() end */ if(duration != -2 && genrelist[genre]) { /* is it an audio file ? */ counter++; switch (format) { case 0: if(duration != -1) { - printf("#EXTINF:%d,%s - %s%s", duration, artist, title, - eol); + printf("#EXTINF:%d,", duration); + if(strlen(artist) != 0) + printf("%s - ", artist); + printf("%s%s", title, eol); } print_path(newpath); printf("%s", eol); @@ -977,8 +1009,10 @@ void parse_file(unsigned char *newpath) case 1: printf("File%d=", counter); print_path(newpath); - printf("%sTitle%d=%s - %s%s", eol, counter, artist, title, - eol); + printf("%sTitle%d=", eol, counter); + if(strlen(artist) != 0) + printf("%s - ", artist); + printf("%s%s", title, eol); if(duration != -1) printf("Length%d=%d%s", counter, duration, eol); break; @@ -1037,7 +1071,7 @@ void parse_file(unsigned char *newpath) printf("\t%s", eol); } break; - case 4: // printing output for Sansa players + case 4: // printing output for Sansa players myplaputstr("HARP, "); myplaputstr(newpath); myplaputstr(eol); @@ -1095,7 +1129,7 @@ int main(int argc, char **argv) winorunix = one2one; basemap = one2one; parse_options(argc, argv); - if(optind == argc) + if(optind == argc && !fromstdin) usage(); switch (format) { case 0: @@ -1138,15 +1172,25 @@ int main(int argc, char **argv) basemap = noand; } break; - case 4: + case 4: { eol = "\r\n"; - myplaputstr( "PLP PLAYLIST\r\nVERSION 1.20\r\n\r\n" ); + myplaputstr("PLP PLAYLIST\r\nVERSION 1.20\r\n\r\n"); } } - for(; optind < argc; optind++) { - parse_directory(argv[optind]); - } + if(fromstdin) { + unsigned char path[PATH_MAX]; + int i; + while(fgets(path, PATH_MAX, stdin)) { + for(i = 0; i < PATH_MAX; i++) + if(path[i] == '\r' || path[i] == '\n') + path[i] = '\0'; + parse_directory(path); + } + } else + for(; optind < argc; optind++) { + parse_directory(argv[optind]); + } switch (format) { case 1: printf("NumberOfEntries=%d%sVersion=2%s", counter, eol, eol); -- 2.20.1