From 3d7d1d4d5b0289c6357e02be70efe2958ae55e0a Mon Sep 17 00:00:00 2001 From: Christian Soffke Date: Tue, 28 May 2024 00:01:57 +0200 Subject: plugins: properties: show track info for whole playlist Track Info can now be displayed for the set of all tracks contained in a playlist. This lets you calculate a playlist's length, for example, even if it is not currently playing. This functionality can be accessed from the existing "Properties" screen for a selected playlist file. A line has been added at the very bottom to show Track Info. Change-Id: I311532b7cfa9e29d46c0cd5623ba4c06c1dd5b5f --- apps/playlist.c | 115 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 42 deletions(-) (limited to 'apps/playlist.c') diff --git a/apps/playlist.c b/apps/playlist.c index 5a3ada8efc..3600918eb3 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -2498,74 +2498,105 @@ int playlist_insert_directory(struct playlist_info* playlist, } /* - * Insert all tracks from specified playlist into dynamic playlist. + * If action_cb is *not* NULL, it will be called for every track contained + * in the playlist specified by filename. If action_cb is NULL, you must + * instead provide a playlist insert context to use for adding each track + * into a dynamic playlist. */ -int playlist_insert_playlist(struct playlist_info* playlist, const char *filename, - int position, bool queue) +bool playlist_entries_iterate(const char *filename, + struct playlist_insert_context *pl_context, + bool (*action_cb)(const char *file_name)) { - int fd = -1; + int fd = -1, i = 0; + bool ret = false; int max; char *dir; char temp_buf[MAX_PATH+1]; char trackname[MAX_PATH+1]; - int result = -1; bool utf8 = is_m3u8_name(filename); - struct playlist_insert_context pl_context; cpu_boost(true); - if (playlist_insert_context_create(playlist, &pl_context, position, queue, true) >= 0) + fd = open_utf8(filename, O_RDONLY); + if (fd < 0) { - fd = open_utf8(filename, O_RDONLY); - if (fd < 0) - { - notify_access_error(); - goto out; - } + notify_access_error(); + goto out; + } - /* we need the directory name for formatting purposes */ - size_t dirlen = path_dirname(filename, (const char **)&dir); - //dir = strmemdupa(dir, dirlen); + /* we need the directory name for formatting purposes */ + size_t dirlen = path_dirname(filename, (const char **)&dir); + //dir = strmemdupa(dir, dirlen); - while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) - { - /* user abort */ - if (action_userabort(TIMEOUT_NOBLOCK)) - break; - if (temp_buf[0] != '#' && temp_buf[0] != '\0') + if (action_cb) + show_search_progress(true, 0); + + while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) + { + /* user abort */ + if (!action_cb && action_userabort(TIMEOUT_NOBLOCK)) + break; + + if (temp_buf[0] != '#' && temp_buf[0] != '\0') + { + i++; + if (!utf8) { - if (!utf8) - { - /* Use trackname as a temporay buffer. Note that trackname must - * be as large as temp_buf. - */ - max = convert_m3u_name(temp_buf, max, sizeof(temp_buf), trackname); - } + /* Use trackname as a temporay buffer. Note that trackname must + * be as large as temp_buf. + */ + max = convert_m3u_name(temp_buf, max, sizeof(temp_buf), trackname); + } - /* we need to format so that relative paths are correctly - handled */ - if (format_track_path(trackname, temp_buf, - sizeof(trackname), dir, dirlen) < 0) - { - goto out; - } + /* we need to format so that relative paths are correctly + handled */ + if (format_track_path(trackname, temp_buf, + sizeof(trackname), dir, dirlen) < 0) + { + goto out; + } - if (playlist_insert_context_add(&pl_context, trackname) < 0) + if (action_cb) + { + if (!action_cb(trackname)) goto out; + else if (!show_search_progress(false, i)) + break; } - - /* let the other threads work */ - yield(); + else if (playlist_insert_context_add(pl_context, trackname) < 0) + goto out; } - } - result = 0; + /* let the other threads work */ + yield(); + } + ret = true; out: close(fd); + cpu_boost(false); + return ret; +} + +/* + * Insert all tracks from specified playlist into dynamic playlist. + */ +int playlist_insert_playlist(struct playlist_info* playlist, const char *filename, + int position, bool queue) +{ + + int result = -1; + + struct playlist_insert_context pl_context; + cpu_boost(true); + + if (playlist_insert_context_create(playlist, &pl_context, position, queue, true) >= 0 + && playlist_entries_iterate(filename, &pl_context, NULL)) + result = 0; + cpu_boost(false); playlist_insert_context_release(&pl_context); return result; -- cgit v1.2.3