Esempio 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;
}
enum playlist_result
playlist_append_file(struct playlist *playlist, const char *path, int uid,
		     unsigned *added_id)
{
	int ret;
	struct stat st;
	struct song *song;

	if (uid < 0) {
		g_debug("unauthenticated client: %d", uid);
		return PLAYLIST_RESULT_DENIED;
    }

	ret = stat(path, &st);
	if (ret < 0)
		return PLAYLIST_RESULT_ERRNO;

	if (st.st_uid != (uid_t)uid && (st.st_mode & 0444) != 0444) {
		g_debug("client is not owner: %d (%o)", st.st_uid, st.st_mode);
		return PLAYLIST_RESULT_DENIED;
    }

	song = song_file_load(path, NULL);
	if (song == NULL)
		return PLAYLIST_RESULT_NO_SUCH_SONG;

	return playlist_append_song(playlist, song, added_id);
}
Esempio n. 3
0
enum playlist_result
playlist_append_file(struct playlist *playlist, struct player_control *pc,
		     const char *path, int uid, unsigned *added_id)
{
	int ret;
	struct stat st;
	struct song *song;

	if (uid <= 0)
		/* unauthenticated client */
		return PLAYLIST_RESULT_DENIED;

	ret = stat(path, &st);
	if (ret < 0)
		return PLAYLIST_RESULT_ERRNO;

	if (st.st_uid != (uid_t)uid && (st.st_mode & 0444) != 0444)
		/* client is not owner */
		return PLAYLIST_RESULT_DENIED;

	song = song_file_load(path, NULL);
	if (song == NULL)
		return PLAYLIST_RESULT_NO_SUCH_SONG;

	return playlist_append_song(playlist, pc, song, added_id);
}
Esempio n. 4
0
static int
directoryAddSongToPlaylist(struct song *song, void *data)
{
	struct player_control *pc = data;

	return playlist_append_song(&g_playlist, pc, song, NULL);
}
Esempio n. 5
0
static int
findAddInDirectory(struct song *song, void *_data)
{
	struct search_data *data = _data;

	if (locate_song_match(song, data->criteria))
		return playlist_append_song(&g_playlist,
					    data->client->player_control,
					    song, NULL);

	return 0;
}
enum playlist_result
playlist_append_uri(struct playlist *playlist, const char *uri,
		    unsigned *added_id)
{
	struct song *song;

	g_debug("add to playlist: %s", uri);

	song = song_by_uri(uri);
	if (song == NULL)
		return PLAYLIST_RESULT_NO_SUCH_SONG;

	return playlist_append_song(playlist, song, added_id);
}
Esempio n. 7
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;
}