Skip to content

Commit 92c2c96

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
1 parent 4035b68 commit 92c2c96

5 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/audacious/dbus-server.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,17 @@ 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+
ENTER_MAIN_THREAD(url)
470+
auto mode =
471+
aud_get_bool("metadata_on_play") ? Playlist::NoWait : Playlist::Wait;
472+
CURRENT.save_to_file(url, mode);
473+
LEAVE_MAIN_THREAD()
474+
FINISH(playlist_save);
475+
return true;
476+
}
477+
467478
static gboolean do_playlist_enqueue_to_temp(Obj * obj, Invoc * invoc,
468479
const char * url)
469480
{
@@ -1045,6 +1056,7 @@ static const struct
10451056
{"handle-play-pause", (GCallback)do_play_pause},
10461057
{"handle-playing", (GCallback)do_playing},
10471058
{"handle-playlist-add", (GCallback)do_playlist_add},
1059+
{"handle-playlist-save", (GCallback)do_playlist_save},
10481060
{"handle-playlist-enqueue-to-temp", (GCallback)do_playlist_enqueue_to_temp},
10491061
{"handle-playlist-ins-url-string", (GCallback)do_playlist_ins_url_string},
10501062
{"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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ 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+
148+
if (argc < 2)
149+
{
150+
audtool_whine_args (argv[0], "<url>");
151+
exit (1);
152+
}
153+
154+
uri = construct_uri (argv[1]);
155+
156+
if (! uri)
157+
exit (1);
158+
159+
obj_audacious_call_playlist_save_sync (dbus_proxy, uri, NULL, NULL);
160+
g_free (uri);
161+
}
162+
144163
void playlist_delete (int argc, char * * argv)
145164
{
146165
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@
366366
<arg type="u" direction="in" name="pos"/>
367367
</method>
368368

369+
<!-- Save playlist to given file path -->
370+
<method name="PlaylistSave">
371+
<arg type="s" direction="in" name="url" />
372+
</method>
373+
369374
<!-- Clear the playlist -->
370375
<method name="Clear" />
371376

0 commit comments

Comments
 (0)