diff options
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 115 |
1 files changed, 73 insertions, 42 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 5a3ada8efc..3600918eb3 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -2498,75 +2498,106 @@ int playlist_insert_directory(struct playlist_info* playlist, | |||
2498 | } | 2498 | } |
2499 | 2499 | ||
2500 | /* | 2500 | /* |
2501 | * Insert all tracks from specified playlist into dynamic playlist. | 2501 | * If action_cb is *not* NULL, it will be called for every track contained |
2502 | * in the playlist specified by filename. If action_cb is NULL, you must | ||
2503 | * instead provide a playlist insert context to use for adding each track | ||
2504 | * into a dynamic playlist. | ||
2502 | */ | 2505 | */ |
2503 | int playlist_insert_playlist(struct playlist_info* playlist, const char *filename, | 2506 | bool playlist_entries_iterate(const char *filename, |
2504 | int position, bool queue) | 2507 | struct playlist_insert_context *pl_context, |
2508 | bool (*action_cb)(const char *file_name)) | ||
2505 | { | 2509 | { |
2506 | int fd = -1; | 2510 | int fd = -1, i = 0; |
2511 | bool ret = false; | ||
2507 | int max; | 2512 | int max; |
2508 | char *dir; | 2513 | char *dir; |
2509 | 2514 | ||
2510 | char temp_buf[MAX_PATH+1]; | 2515 | char temp_buf[MAX_PATH+1]; |
2511 | char trackname[MAX_PATH+1]; | 2516 | char trackname[MAX_PATH+1]; |
2512 | 2517 | ||
2513 | int result = -1; | ||
2514 | bool utf8 = is_m3u8_name(filename); | 2518 | bool utf8 = is_m3u8_name(filename); |
2515 | 2519 | ||
2516 | struct playlist_insert_context pl_context; | ||
2517 | cpu_boost(true); | 2520 | cpu_boost(true); |
2518 | 2521 | ||
2519 | if (playlist_insert_context_create(playlist, &pl_context, position, queue, true) >= 0) | 2522 | fd = open_utf8(filename, O_RDONLY); |
2523 | if (fd < 0) | ||
2520 | { | 2524 | { |
2521 | fd = open_utf8(filename, O_RDONLY); | 2525 | notify_access_error(); |
2522 | if (fd < 0) | 2526 | goto out; |
2523 | { | 2527 | } |
2524 | notify_access_error(); | ||
2525 | goto out; | ||
2526 | } | ||
2527 | 2528 | ||
2528 | /* we need the directory name for formatting purposes */ | 2529 | /* we need the directory name for formatting purposes */ |
2529 | size_t dirlen = path_dirname(filename, (const char **)&dir); | 2530 | size_t dirlen = path_dirname(filename, (const char **)&dir); |
2530 | //dir = strmemdupa(dir, dirlen); | 2531 | //dir = strmemdupa(dir, dirlen); |
2531 | 2532 | ||
2532 | while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) | ||
2533 | { | ||
2534 | /* user abort */ | ||
2535 | if (action_userabort(TIMEOUT_NOBLOCK)) | ||
2536 | break; | ||
2537 | 2533 | ||
2538 | if (temp_buf[0] != '#' && temp_buf[0] != '\0') | 2534 | if (action_cb) |
2535 | show_search_progress(true, 0); | ||
2536 | |||
2537 | while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) | ||
2538 | { | ||
2539 | /* user abort */ | ||
2540 | if (!action_cb && action_userabort(TIMEOUT_NOBLOCK)) | ||
2541 | break; | ||
2542 | |||
2543 | if (temp_buf[0] != '#' && temp_buf[0] != '\0') | ||
2544 | { | ||
2545 | i++; | ||
2546 | if (!utf8) | ||
2539 | { | 2547 | { |
2540 | if (!utf8) | 2548 | /* Use trackname as a temporay buffer. Note that trackname must |
2541 | { | 2549 | * be as large as temp_buf. |
2542 | /* Use trackname as a temporay buffer. Note that trackname must | 2550 | */ |
2543 | * be as large as temp_buf. | 2551 | max = convert_m3u_name(temp_buf, max, sizeof(temp_buf), trackname); |
2544 | */ | 2552 | } |
2545 | max = convert_m3u_name(temp_buf, max, sizeof(temp_buf), trackname); | ||
2546 | } | ||
2547 | 2553 | ||
2548 | /* we need to format so that relative paths are correctly | 2554 | /* we need to format so that relative paths are correctly |
2549 | handled */ | 2555 | handled */ |
2550 | if (format_track_path(trackname, temp_buf, | 2556 | if (format_track_path(trackname, temp_buf, |
2551 | sizeof(trackname), dir, dirlen) < 0) | 2557 | sizeof(trackname), dir, dirlen) < 0) |
2552 | { | 2558 | { |
2553 | goto out; | 2559 | goto out; |
2554 | } | 2560 | } |
2555 | 2561 | ||
2556 | if (playlist_insert_context_add(&pl_context, trackname) < 0) | 2562 | if (action_cb) |
2563 | { | ||
2564 | if (!action_cb(trackname)) | ||
2557 | goto out; | 2565 | goto out; |
2566 | else if (!show_search_progress(false, i)) | ||
2567 | break; | ||
2558 | } | 2568 | } |
2559 | 2569 | else if (playlist_insert_context_add(pl_context, trackname) < 0) | |
2560 | /* let the other threads work */ | 2570 | goto out; |
2561 | yield(); | ||
2562 | } | 2571 | } |
2563 | } | ||
2564 | 2572 | ||
2565 | result = 0; | 2573 | /* let the other threads work */ |
2574 | yield(); | ||
2575 | } | ||
2576 | ret = true; | ||
2566 | 2577 | ||
2567 | out: | 2578 | out: |
2568 | close(fd); | 2579 | close(fd); |
2569 | cpu_boost(false); | 2580 | cpu_boost(false); |
2581 | return ret; | ||
2582 | } | ||
2583 | |||
2584 | /* | ||
2585 | * Insert all tracks from specified playlist into dynamic playlist. | ||
2586 | */ | ||
2587 | int playlist_insert_playlist(struct playlist_info* playlist, const char *filename, | ||
2588 | int position, bool queue) | ||
2589 | { | ||
2590 | |||
2591 | int result = -1; | ||
2592 | |||
2593 | struct playlist_insert_context pl_context; | ||
2594 | cpu_boost(true); | ||
2595 | |||
2596 | if (playlist_insert_context_create(playlist, &pl_context, position, queue, true) >= 0 | ||
2597 | && playlist_entries_iterate(filename, &pl_context, NULL)) | ||
2598 | result = 0; | ||
2599 | |||
2600 | cpu_boost(false); | ||
2570 | playlist_insert_context_release(&pl_context); | 2601 | playlist_insert_context_release(&pl_context); |
2571 | return result; | 2602 | return result; |
2572 | } | 2603 | } |