From 49616db1faede67655d15172045eabb8ef1fa6ea Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 17 Jul 2017 10:12:48 +0200 Subject: Debug and numerical tags year and track in regex mode --- regex.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index b7f19aa..0b01347 100644 --- a/regex.c +++ b/regex.c @@ -101,11 +101,19 @@ void regexSelection(menuC* menu, const char* msg) { } } } +/* + * Example regex : + * + * ^([a-Z0-9 ]+) - ([^\[]+)\[([0-9]+)\]/atn + * (Daft Punk) - Something about us[11].mp3 + + */ void regexXtract(itemC* it, const char* msg) { - char* tmp = strrchr( msg , '/' ); - if( !msg || !*msg || !tmp) { + if( !msg || !*msg) { return; } + char* tmp = strrchr( msg , '/' ); + if( !tmp ) return; char *regexS = malloc(tmp-msg+1); @@ -118,9 +126,13 @@ void regexXtract(itemC* it, const char* msg) { int nbR = strlen(tmp); tab = malloc( sizeof *tab * (nbR+1)); if( match_regex(regexS, line, tab, nbR ) ) { +#ifdef DEBUG fprintf(stderr, "Hello"); +#endif for(int i = 0 ; i < nbR ; i++) { +#ifdef DEBUG fprintf(stderr, "<<%s>>\n", tab[i]); +#endif switch(tmp[i]) { case 't': taglib_tag_set_title(it->info.tag, tab[i]); @@ -132,8 +144,20 @@ void regexXtract(itemC* it, const char* msg) { taglib_tag_set_album(it->info.tag, tab[i]); break; case 'y': + { + unsigned int t = 0; + int r = sscanf(tab[i], "%u", &t); + if( r == 1) + taglib_tag_set_year(it->info.tag, t); break; + } case 'n': + { + unsigned int t = 0; + int r = sscanf(tab[i], "%u", &t); + if( r == 1) + taglib_tag_set_track(it->info.tag, t); + } break; case 'g': taglib_tag_set_genre(it->info.tag, tab[i]); -- cgit v1.2.3