예제 #1
0
파일: playlist_queue.c 프로젝트: seebag/mpd
enum playlist_result
playlist_open_into_queue(const char *uri,
                         unsigned start_index, unsigned end_index,
                         struct playlist *dest, struct player_control *pc,
                         bool secure)
{
    GMutex *mutex = g_mutex_new();
    GCond *cond = g_cond_new();

    struct input_stream *is;
    struct playlist_provider *playlist =
    playlist_open_any(uri, mutex, cond, &is);
    if (playlist == NULL) {
        g_cond_free(cond);
        g_mutex_free(mutex);
        return PLAYLIST_RESULT_NO_SUCH_LIST;
    }

    enum playlist_result result =
        playlist_load_into_queue(uri, playlist, start_index, end_index,
                                 dest, pc, secure);
    playlist_plugin_close(playlist);

    if (is != NULL)
        input_stream_close(is);

    g_cond_free(cond);
    g_mutex_free(mutex);

    return result;
}
예제 #2
0
static void
lastfm_close(struct playlist_provider *_playlist)
{
	struct lastfm_playlist *playlist = (struct lastfm_playlist *)_playlist;

	playlist_plugin_close(playlist->xspf);
	input_stream_close(playlist->is);
	g_free(playlist);
}
enum playlist_result
playlist_open_into_queue(const char *uri, struct playlist *dest)
{
	if (uri_has_scheme(uri))
		return playlist_open_remote_into_queue(uri, dest);

	struct playlist_provider *playlist = playlist_mapper_open(uri);
	if (playlist != NULL) {
		enum playlist_result result =
			playlist_load_into_queue(uri, playlist, dest);
		playlist_plugin_close(playlist);
		return result;
	}

	return PLAYLIST_RESULT_NO_SUCH_LIST;
}
예제 #4
0
enum playlist_result
playlist_open_into_queue(const char *uri,
			 struct playlist *dest, struct player_control *pc,
			 bool secure)
{
	struct input_stream *is;
	struct playlist_provider *playlist = playlist_open_any(uri, &is);
	if (playlist == NULL)
		return PLAYLIST_RESULT_NO_SUCH_LIST;

	enum playlist_result result =
		playlist_load_into_queue(uri, playlist, dest, pc, secure);
	playlist_plugin_close(playlist);

	if (is != NULL)
		input_stream_close(is);

	return result;
}
static enum playlist_result
playlist_open_remote_into_queue(const char *uri, struct playlist *dest)
{
	GError *error = NULL;
	struct playlist_provider *playlist;
	struct input_stream *is = NULL;
	enum playlist_result result;

	assert(uri_has_scheme(uri));

	playlist = playlist_list_open_uri(uri);
	if (playlist == NULL) {
		is = input_stream_open(uri, &error);
		if (is == NULL) {
			if (error != NULL) {
				g_warning("Failed to open %s: %s",
					  uri, error->message);
				g_error_free(error);
			}

			return PLAYLIST_RESULT_NO_SUCH_LIST;
		}

		playlist = playlist_list_open_stream(is, uri);
		if (playlist == NULL) {
			input_stream_close(is);
			return PLAYLIST_RESULT_NO_SUCH_LIST;
		}
	}

	result = playlist_load_into_queue(uri, playlist, dest);
	playlist_plugin_close(playlist);

	if (is != NULL)
		input_stream_close(is);

	return result;
}
예제 #6
0
파일: dump_playlist.c 프로젝트: seebag/mpd
int main(int argc, char **argv)
{
	const char *uri;
	struct input_stream *is = NULL;
	bool success;
	GError *error = NULL;
	struct playlist_provider *playlist;
	struct song *song;

	if (argc != 3) {
		g_printerr("Usage: dump_playlist CONFIG URI\n");
		return 1;
	}

	uri = argv[2];

	/* initialize GLib */

	g_thread_init(NULL);
	g_log_set_default_handler(my_log_func, NULL);

	/* initialize MPD */

	config_global_init();
	success = config_read_file(argv[1], &error);
	if (!success) {
		g_printerr("%s\n", error->message);
		g_error_free(error);
		return 1;
	}

	io_thread_init();
	if (!io_thread_start(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	if (!input_stream_global_init(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return 2;
	}

	playlist_list_global_init();
	decoder_plugin_init_all();

	/* open the playlist */

	GMutex *mutex = g_mutex_new();
	GCond *cond = g_cond_new();

	playlist = playlist_list_open_uri(uri, mutex, cond);
	if (playlist == NULL) {
		/* open the stream and wait until it becomes ready */

		is = input_stream_open(uri, mutex, cond, &error);
		if (is == NULL) {
			if (error != NULL) {
				g_warning("%s", error->message);
				g_error_free(error);
			} else
				g_printerr("input_stream_open() failed\n");
			return 2;
		}

		input_stream_lock_wait_ready(is);

		/* open the playlist */

		playlist = playlist_list_open_stream(is, uri);
		if (playlist == NULL) {
			input_stream_close(is);
			g_printerr("Failed to open playlist\n");
			return 2;
		}
	}

	/* dump the playlist */

	while ((song = playlist_plugin_read(playlist)) != NULL) {
		g_print("%s\n", song->uri);

		if (song->end_ms > 0)
			g_print("range: %u:%02u..%u:%02u\n",
				song->start_ms / 60000,
				(song->start_ms / 1000) % 60,
				song->end_ms / 60000,
				(song->end_ms / 1000) % 60);
		else if (song->start_ms > 0)
			g_print("range: %u:%02u..\n",
				song->start_ms / 60000,
				(song->start_ms / 1000) % 60);

		if (song->tag != NULL)
			tag_save(stdout, song->tag);

		song_free(song);
	}

	/* deinitialize everything */

	playlist_plugin_close(playlist);
	if (is != NULL)
		input_stream_close(is);

	g_cond_free(cond);
	g_mutex_free(mutex);

	decoder_plugin_deinit_all();
	playlist_list_global_finish();
	input_stream_global_finish();
	io_thread_deinit();
	config_global_finish();

	return 0;
}