Exemplo n.º 1
0
enum playlist_result
playlist_load_into_queue(const char *uri, struct playlist_provider *source,
			 struct playlist *dest, struct player_control *pc,
			 bool secure)
{
	enum playlist_result result;
	struct song *song;
	char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;

	while ((song = playlist_plugin_read(source)) != NULL) {
		song = playlist_check_translate_song(song, base_uri, secure);
		if (song == NULL)
			continue;

		result = playlist_append_song(dest, pc, song, NULL);
		if (result != PLAYLIST_RESULT_SUCCESS) {
			if (!song_in_database(song))
				song_free(song);
			g_free(base_uri);
			return result;
		}
	}

	g_free(base_uri);

	return PLAYLIST_RESULT_SUCCESS;
}
Exemplo n.º 2
0
static struct song *
lastfm_read(struct playlist_provider *_playlist)
{
	struct lastfm_playlist *playlist = (struct lastfm_playlist *)_playlist;

	return playlist_plugin_read(playlist->xspf);
}
Exemplo n.º 3
0
enum playlist_result
playlist_load_into_queue(const char *uri, struct playlist_provider *source,
                         unsigned start_index, unsigned end_index,
                         struct playlist *dest, struct player_control *pc,
                         bool secure)
{
    enum playlist_result result;
    struct song *song;
    char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;

    for (unsigned i = 0;
    i < end_index && (song = playlist_plugin_read(source)) != NULL;
    ++i) {
        if (i < start_index) {
            /* skip songs before the start index */
            song_free(song);
            continue;
        }

        song = playlist_check_translate_song(song, base_uri, secure);
        if (song == NULL)
            continue;

#ifdef ENABLE_DESPOTIFY
// Not the right place to do this...
        if (strcmp(g_uri_parse_scheme(song->uri), "spt") == 0) {
            g_debug("Despotify update info : %s\n", song->uri);
            struct song *song_new;
            song_new = despotify_update_song(song);
            if (song_new != NULL) {
                song = song_new;
            }
        }
#endif

        result = playlist_append_song(dest, pc, song, NULL);
        song_free(song);
        if (result != PLAYLIST_RESULT_SUCCESS) {
            g_free(base_uri);
            return result;
        }
    }

    g_free(base_uri);

    return PLAYLIST_RESULT_SUCCESS;
}
Exemplo n.º 4
0
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;
}