2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "playlist_queue.h"
22 #include "playlist_list.h"
23 #include "playlist_plugin.h"
24 #include "playlist_mapper.h"
25 #include "playlist_song.h"
26 #include "stored_playlist.h"
30 #include "input_stream.h"
33 playlist_load_into_queue(const char *uri
, struct playlist_provider
*source
,
34 struct playlist
*dest
)
36 enum playlist_result result
;
38 char *base_uri
= uri
!= NULL
? g_path_get_dirname(uri
) : NULL
;
40 while ((song
= playlist_plugin_read(source
)) != NULL
) {
41 song
= playlist_check_translate_song(song
, base_uri
);
45 result
= playlist_append_song(dest
, song
, NULL
);
46 if (result
!= PLAYLIST_RESULT_SUCCESS
) {
47 if (!song_in_database(song
))
56 return PLAYLIST_RESULT_SUCCESS
;
59 static enum playlist_result
60 playlist_open_remote_into_queue(const char *uri
, struct playlist
*dest
)
63 struct playlist_provider
*playlist
;
64 struct input_stream
*is
= NULL
;
65 enum playlist_result result
;
67 assert(uri_has_scheme(uri
));
69 playlist
= playlist_list_open_uri(uri
);
70 if (playlist
== NULL
) {
71 is
= input_stream_open(uri
, &error
);
74 g_warning("Failed to open %s: %s",
79 return PLAYLIST_RESULT_NO_SUCH_LIST
;
82 playlist
= playlist_list_open_stream(is
, uri
);
83 if (playlist
== NULL
) {
84 input_stream_close(is
);
85 return PLAYLIST_RESULT_NO_SUCH_LIST
;
89 result
= playlist_load_into_queue(uri
, playlist
, dest
);
90 playlist_plugin_close(playlist
);
93 input_stream_close(is
);
99 playlist_open_into_queue(const char *uri
, struct playlist
*dest
)
101 if (uri_has_scheme(uri
))
102 return playlist_open_remote_into_queue(uri
, dest
);
104 struct playlist_provider
*playlist
= playlist_mapper_open(uri
);
105 if (playlist
!= NULL
) {
106 enum playlist_result result
=
107 playlist_load_into_queue(uri
, playlist
, dest
);
108 playlist_plugin_close(playlist
);
112 return PLAYLIST_RESULT_NO_SUCH_LIST
;