Skip to content

Commit 6d4a447

Browse files
audtool: Support exporting playlists via CLI. Closes: #1659
The format is determined by the file extension, similar to when exporting playlists from the GUI. Example usage: - audtool playlist-save file.m3u - audtool playlist-save /tmp/file.audpl - audtool playlist-save file:///tmp/file.asx - audtool --select-displayed playlist-save file.pls
1 parent 4035b68 commit 6d4a447

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/audacious/dbus-server.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,18 @@ static gboolean do_playlist_add(Obj * obj, Invoc * invoc, const char * list)
464464
return true;
465465
}
466466

467+
static gboolean do_playlist_save(Obj * obj, Invoc * invoc, const char * url)
468+
{
469+
bool success;
470+
ENTER_MAIN_THREAD(url, &success)
471+
auto mode =
472+
aud_get_bool("metadata_on_play") ? Playlist::NoWait : Playlist::Wait;
473+
success = CURRENT.save_to_file(url, mode);
474+
LEAVE_MAIN_THREAD()
475+
FINISH2(playlist_save, success);
476+
return true;
477+
}
478+
467479
static gboolean do_playlist_enqueue_to_temp(Obj * obj, Invoc * invoc,
468480
const char * url)
469481
{
@@ -1045,6 +1057,7 @@ static const struct
10451057
{"handle-play-pause", (GCallback)do_play_pause},
10461058
{"handle-playing", (GCallback)do_playing},
10471059
{"handle-playlist-add", (GCallback)do_playlist_add},
1060+
{"handle-playlist-save", (GCallback)do_playlist_save},
10481061
{"handle-playlist-enqueue-to-temp", (GCallback)do_playlist_enqueue_to_temp},
10491062
{"handle-playlist-ins-url-string", (GCallback)do_playlist_ins_url_string},
10501063
{"handle-playqueue-add", (GCallback)do_playqueue_add},

src/audtool/audtool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void playlist_display (int, char * *);
7878
void playlist_position (int, char * *);
7979
void playlist_jump (int, char * *);
8080
void playlist_add_url_string (int, char * *);
81+
void playlist_save (int, char * *);
8182
void playlist_delete (int, char * *);
8283
void playlist_clear (int, char * *);
8384
void playlist_repeat_status (int, char * *);

src/audtool/handlers_playlist.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,36 @@ void playlist_add_url_string (int argc, char * * argv)
141141
g_free (uri);
142142
}
143143

144+
void playlist_save (int argc, char * * argv)
145+
{
146+
char * uri;
147+
gboolean success = FALSE;
148+
149+
if (argc < 2)
150+
{
151+
audtool_whine_args (argv[0], "<url>");
152+
exit (1);
153+
}
154+
155+
uri = construct_uri (argv[1]);
156+
157+
if (! uri)
158+
exit (1);
159+
160+
obj_audacious_call_playlist_save_sync (dbus_proxy, uri, & success, NULL, NULL);
161+
162+
if (! success)
163+
{
164+
audtool_report ("Error saving %s:\nMake sure to use a supported "
165+
"file extension and that the respective playlist "
166+
"plugin is enabled.", uri);
167+
g_free (uri);
168+
exit (1);
169+
}
170+
else
171+
g_free (uri);
172+
}
173+
144174
void playlist_delete (int argc, char * * argv)
145175
{
146176
int pos = check_args_playlist_pos (argc, argv);

src/audtool/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const struct commandhandler handlers[] =
9292
{"playlist-shuffle-toggle", playlist_shuffle_toggle, "toggle playlist shuffle", 0},
9393
{"playlist-stop-after-status", playlist_stop_after_status, "query if stopping after current song", 0},
9494
{"playlist-stop-after-toggle", playlist_stop_after_toggle, "toggle if stopping after current song", 0},
95+
{"playlist-save", playlist_save, "save playlist to given file path", 1},
9596

9697
{"<sep>", NULL, "More playlist commands", 0},
9798
{"number-of-playlists", number_of_playlists, "print number of playlists", 0},

src/dbus/aud-dbus.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@
366366
<arg type="u" direction="in" name="pos"/>
367367
</method>
368368

369+
<!-- Save the playlist to given file path -->
370+
<method name="PlaylistSave">
371+
<arg type="s" direction="in" name="url"/>
372+
<arg type="b" direction="out" name="success"/>
373+
</method>
374+
369375
<!-- Clear the playlist -->
370376
<method name="Clear" />
371377

0 commit comments

Comments
 (0)