diff options
Diffstat (limited to 'apps/playlist_catalog.c')
-rw-r--r-- | apps/playlist_catalog.c | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index b6939208ac..be992645ee 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c | |||
@@ -389,6 +389,43 @@ bool catalog_view_playlists(void) | |||
389 | return (display_playlists(NULL, CATBROWSE_CATVIEW) >= 0); | 389 | return (display_playlists(NULL, CATBROWSE_CATVIEW) >= 0); |
390 | } | 390 | } |
391 | 391 | ||
392 | static void apply_playlist_extension(char* buf, size_t buf_size) | ||
393 | { | ||
394 | size_t len = strlen(buf); | ||
395 | if(len > 4 && !strcasecmp(&buf[len-4], ".m3u")) | ||
396 | strlcat(buf, "8", buf_size); | ||
397 | else if(len <= 5 || strcasecmp(&buf[len-5], ".m3u8")) | ||
398 | strlcat(buf, ".m3u8", buf_size); | ||
399 | } | ||
400 | |||
401 | static int remove_extension(char* path) | ||
402 | { | ||
403 | char *dot = strrchr(path, '.'); | ||
404 | if (dot) | ||
405 | *dot = '\0'; | ||
406 | |||
407 | return 0; | ||
408 | } | ||
409 | |||
410 | |||
411 | bool catalog_pick_new_playlist_name(char *pl_name, size_t buf_size, | ||
412 | const char* curr_pl_name) | ||
413 | { | ||
414 | bool do_save = false; | ||
415 | while (!do_save && !remove_extension(pl_name) && | ||
416 | !kbd_input(pl_name, buf_size - 7, NULL)) | ||
417 | { | ||
418 | do_save = true; | ||
419 | apply_playlist_extension(pl_name, buf_size); | ||
420 | |||
421 | /* warn before overwriting existing (different) playlist */ | ||
422 | if ((!curr_pl_name || strcmp(curr_pl_name, pl_name)) && | ||
423 | file_exists(pl_name)) | ||
424 | do_save = confirm_overwrite_yesno() == YESNO_YES; | ||
425 | } | ||
426 | return do_save; | ||
427 | } | ||
428 | |||
392 | static int (*ctx_add_to_playlist)(const char* playlist, bool new_playlist); | 429 | static int (*ctx_add_to_playlist)(const char* playlist, bool new_playlist); |
393 | bool catalog_add_to_a_playlist(const char* sel, int sel_attr, | 430 | bool catalog_add_to_a_playlist(const char* sel, int sel_attr, |
394 | bool new_playlist, char *m3u8name, | 431 | bool new_playlist, char *m3u8name, |
@@ -404,7 +441,6 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr, | |||
404 | 441 | ||
405 | if (new_playlist) | 442 | if (new_playlist) |
406 | { | 443 | { |
407 | size_t len; | ||
408 | if (m3u8name == NULL) | 444 | if (m3u8name == NULL) |
409 | { | 445 | { |
410 | const char *name; | 446 | const char *name; |
@@ -425,14 +461,10 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr, | |||
425 | else | 461 | else |
426 | strmemccpy(playlist, m3u8name, MAX_PATH); | 462 | strmemccpy(playlist, m3u8name, MAX_PATH); |
427 | 463 | ||
428 | if (kbd_input(playlist, MAX_PATH, NULL)) | 464 | apply_playlist_extension(playlist, sizeof(playlist)); |
465 | |||
466 | if (!catalog_pick_new_playlist_name(playlist, sizeof(playlist), NULL)) | ||
429 | return false; | 467 | return false; |
430 | |||
431 | len = strlen(playlist); | ||
432 | if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u")) | ||
433 | strlcat(playlist, "8", sizeof(playlist)); | ||
434 | else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8")) | ||
435 | strlcat(playlist, ".m3u8", sizeof(playlist)); | ||
436 | } | 468 | } |
437 | else | 469 | else |
438 | { | 470 | { |