diff options
Diffstat (limited to 'apps/metadata.c')
-rw-r--r-- | apps/metadata.c | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/apps/metadata.c b/apps/metadata.c index 9403625eda..12bea286d0 100644 --- a/apps/metadata.c +++ b/apps/metadata.c | |||
@@ -435,39 +435,55 @@ enum { AUTORESUMABLE_UNKNOWN = 0, AUTORESUMABLE_TRUE, AUTORESUMABLE_FALSE }; | |||
435 | 435 | ||
436 | bool autoresumable(struct mp3entry *id3) | 436 | bool autoresumable(struct mp3entry *id3) |
437 | { | 437 | { |
438 | unsigned char search[MAX_PATHNAME+1]; | 438 | char *endp, *path; |
439 | char *saveptr, *substr; | 439 | size_t len; |
440 | bool is_resumable; | 440 | bool is_resumable; |
441 | 441 | ||
442 | if (id3->autoresumable) /* result cached? */ | 442 | if (id3->autoresumable) /* result cached? */ |
443 | return id3->autoresumable == AUTORESUMABLE_TRUE; | 443 | return id3->autoresumable == AUTORESUMABLE_TRUE; |
444 | 444 | ||
445 | is_resumable = true; | 445 | is_resumable = false; |
446 | 446 | ||
447 | strcpy(search, global_settings.autoresume_strpat); | 447 | if (id3->path) |
448 | |||
449 | for (substr = strtok_r(search, ",", &saveptr); | ||
450 | substr; | ||
451 | substr = strtok_r(NULL, ",", &saveptr)) | ||
452 | { | 448 | { |
453 | if (id3->path && strcasestr(id3->path, substr)) | 449 | for (path = global_settings.autoresume_paths; |
454 | goto out; | 450 | *path; /* search terms left? */ |
455 | if (id3->genre_string && strcasestr(id3->genre_string, substr)) | 451 | path++) |
456 | goto out; | 452 | { |
453 | if (*path == ':') /* Skip empty search patterns */ | ||
454 | continue; | ||
455 | |||
456 | /* FIXME: As soon as strcspn or strchrnul are made available in | ||
457 | the core, the following can be made more efficient. */ | ||
458 | endp = strchr(path, ':'); | ||
459 | if (endp) | ||
460 | len = endp - path; | ||
461 | else | ||
462 | len = strlen(path); | ||
463 | |||
464 | /* Note: At this point, len is always > 0 */ | ||
465 | |||
466 | if (strncasecmp(id3->path, path, len) == 0) | ||
467 | { | ||
468 | /* Full directory-name matches only. Trailing '/' in | ||
469 | search path OK. */ | ||
470 | if (id3->path[len] == '/' || id3->path[len - 1] == '/') | ||
471 | { | ||
472 | is_resumable = true; | ||
473 | break; | ||
474 | } | ||
475 | } | ||
476 | path += len - 1; | ||
477 | } | ||
457 | } | 478 | } |
458 | |||
459 | is_resumable = false; | ||
460 | 479 | ||
461 | out: | ||
462 | /* cache result */ | 480 | /* cache result */ |
463 | id3->autoresumable = | 481 | id3->autoresumable = |
464 | is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; | 482 | is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; |
465 | 483 | ||
466 | logf("autoresumable: %s with genre %s is%s resumable", | 484 | logf("autoresumable: %s is%s resumable", |
467 | id3->path, | 485 | id3->path, is_resumable ? "" : " not"); |
468 | id3->genre_string ? id3->genre_string : "(NULL)", | 486 | |
469 | is_resumable ? "" : " not"); | ||
470 | |||
471 | return is_resumable; | 487 | return is_resumable; |
472 | } | 488 | } |
473 | 489 | ||