Beispiel #1
0
SxPlaylist::SxPlaylist(sp_playlist* spPlaylist, int index, bool isFolder) {
    m_spPlaylist = spPlaylist;
    m_isValid = true;
    m_isFolder = isFolder;
    m_index = index;
    m_thumb = NULL;

    if (!isFolder) {
        if (sp_playlist_is_loaded(spPlaylist)) reLoad();
        m_plCallbacks.description_changed = 0;
        m_plCallbacks.image_changed = 0;
        m_plCallbacks.playlist_metadata_updated = &cb_playlist_metadata_updated;
        m_plCallbacks.playlist_renamed = &cb_playlist_renamed;
        m_plCallbacks.playlist_state_changed = &cb_state_change;
        m_plCallbacks.playlist_update_in_progress = 0;
        m_plCallbacks.subscribers_changed = 0;
        m_plCallbacks.track_created_changed = 0;
        m_plCallbacks.track_message_changed = 0;
        m_plCallbacks.track_seen_changed = 0;
        m_plCallbacks.tracks_added = &cb_tracks_added;
        m_plCallbacks.tracks_moved = &cb_tracks_moved;
        m_plCallbacks.tracks_removed = &cb_tracks_removed;

        sp_playlist_add_callbacks(spPlaylist, &m_plCallbacks, this);
    }
}
Beispiel #2
0
static void SP_CALLCONV pc_playlist_added(sp_playlistcontainer *pc, sp_playlist *playlist, int position, void *userdata) {
	static sp_playlist_callbacks *callbacks;
	MLTREEITEM item;

	if(callbacks == NULL) {
		callbacks = (sp_playlist_callbacks *)malloc(sizeof(sp_playlist_callbacks));
		memset(callbacks, 0, sizeof(sp_playlist_callbacks));

		callbacks->tracks_added = pl_tracks_added;
		callbacks->playlist_renamed = playlist_renamed;
	}

	/* Snoop on the playlist to know when it's named and tracks are added */
	sp_playlist_add_callbacks(playlist, callbacks, NULL);


	/* Add playlist to our Media Library tree */
	item.size = sizeof(MLTREEITEM);
	item.parentId		= m_TreeRootId;
	item.hasChildren	= 0;
	item.id				= 0;
	item.imageIndex		= 0;
	item.title			= "(Loading...)";
	
	/* Create a new entry in under our tree in the Media Library pane */
	SendMessage(hwndLibraryParent, WM_ML_IPC, (WPARAM) &item, ML_IPC_TREEITEM_ADD);
	DSFYDEBUG("New id of entry '%s' is '%u'\n", item.title, item.id);

	/* Add mapping between tree ID and playlist position in playlist container */
	tpAdd(item.id, position);
}
/**
 * This callback is called when an attempt to login has succeeded or failed.
 *
 * @sa sp_session_callbacks#logged_in
 */
static void logged_in(sp_session *sess, sp_error error)
{
	sp_playlistcontainer *pc = sp_session_playlistcontainer(sess);
	int i;

	if (SP_ERROR_OK != error) {
		fprintf(stderr, "jukebox: Login failed: %s\n",
			sp_error_message(error));
		exit(2);
	}

	sp_playlistcontainer_add_callbacks(
		pc,
		&pc_callbacks,
		NULL);

	printf("jukebox: Looking at %d playlists\n", sp_playlistcontainer_num_playlists(pc));

	for (i = 0; i < sp_playlistcontainer_num_playlists(pc); ++i) {
		sp_playlist *pl = sp_playlistcontainer_playlist(pc, i);

		sp_playlist_add_callbacks(pl, &pl_callbacks, NULL);

		if (!strcasecmp(sp_playlist_name(pl), g_listname)) {
			g_jukeboxlist = pl;
			try_jukebox_start();
		}
	}

	if (!g_jukeboxlist) {
		printf("jukebox: No such playlist. Waiting for one to pop up...\n");
		fflush(stdout);
	}
}
Beispiel #4
0
int cmd_playlist_add_track(int argc, char **argv)
{
	sp_link *plink, *tlink;
	sp_track *t;
	sp_playlist *pl;
	int i;
	struct pl_update_work *puw;

	if(argc < 4) {
		printf("add [playlist uri] [position] [track uri] <[track uri]>...\n");
		return 1;
	}

	plink = sp_link_create_from_string(argv[1]);
	if (!plink) {
		fprintf(stderr, "%s is not a spotify link\n", argv[1]);
		return -1;
	}

	if(sp_link_type(plink) != SP_LINKTYPE_PLAYLIST) {
		fprintf(stderr, "%s is not a playlist link\n", argv[1]);
		sp_link_release(plink);
		return -1;
	}

	puw = malloc(sizeof(struct pl_update_work));
	puw->position = atoi(argv[2]);
	puw->tracks = malloc(sizeof(sp_track *) * argc - 3);
	puw->num_tracks = 0;
	for(i = 0; i < argc - 3; i++) {
		tlink = sp_link_create_from_string(argv[i + 3]);
		if(tlink == NULL) {
			fprintf(stderr, "%s is not a spotify link, skipping\n", argv[i + 3]);
			continue;
		}
		if(sp_link_type(tlink) != SP_LINKTYPE_TRACK) {
			fprintf(stderr, "%s is not a track link, skipping\n", argv[i + 3]);
			continue;
		}
		t = sp_link_as_track(tlink);
		sp_track_add_ref(t);
		puw->tracks[puw->num_tracks++] = t;
		sp_link_release(tlink);
	}

	pl = sp_playlist_create(g_session, plink);
	if(!apply_changes(pl, puw)) {
		// Changes applied directly, we're done
		sp_playlist_release(pl);
		sp_link_release(plink);
		return 1;
	}

	fprintf(stderr, "Playlist not yet loaded, waiting...\n");
	sp_playlist_add_callbacks(pl, &pl_update_callbacks, puw);
	sp_link_release(plink);
	return 0;
}
Beispiel #5
0
/**
 * Callback from libspotify, telling us the rootlist is fully synchronized
 *
 * @param  pc            The playlist container handle
 * @param  userdata      The opaque pointer
 */
static void container_loaded ( sp_playlistcontainer *pc, void *userdata )
{
    char *folderName = malloc ( sizeof ( char ) * ( MAX_LENGTH_FOLDER_NAME ) );
    int i;


    if ( folderName == NULL )
    {
        fprintf ( stderr, "jahspotify: Could not allocate folder name variable)\n" );
        return;
    }

    // fprintf ( stderr, "jahspotify: Rootlist synchronized (%d playlists)\n",sp_playlistcontainer_num_playlists ( pc ) );
    signalSynchStarting(sp_playlistcontainer_num_playlists (pc));

    for ( i = 0; i < sp_playlistcontainer_num_playlists ( pc ); ++i )
    {
        sp_playlist *pl = sp_playlistcontainer_playlist ( pc, i );
        sp_playlist_add_callbacks ( pl, &pl_callbacks, NULL );

        sp_link *link = sp_link_create_from_playlist(pl);

        char *linkStr = malloc(sizeof(char) * 100);
        if (link)
        {
            sp_link_add_ref(link);
            sp_link_as_string(link,linkStr,100);
        }
        else
        {
            strcpy(linkStr,"N/A\0");
        }
        switch ( sp_playlistcontainer_playlist_type ( pc,i ) )
        {
          case SP_PLAYLIST_TYPE_PLAYLIST:
            signalPlaylistSeen(sp_playlist_name ( pl ),linkStr);
            break;
          case SP_PLAYLIST_TYPE_START_FOLDER:
            sp_playlistcontainer_playlist_folder_name ( pc,i,folderName, MAX_LENGTH_FOLDER_NAME);
            signalStartFolderSeen(folderName, sp_playlistcontainer_playlist_folder_id(pc,i));
            break;
          case SP_PLAYLIST_TYPE_END_FOLDER:
            sp_playlistcontainer_playlist_folder_name ( pc,i,folderName,MAX_LENGTH_FOLDER_NAME);
            signalEndFolderSeen();
            break;
          case SP_PLAYLIST_TYPE_PLACEHOLDER:
            fprintf ( stderr,"jahspotify: placeholder\n");
        }

        if (link)
            sp_link_release(link);
        free(linkStr);
    }
    signalSynchCompleted();
    free ( folderName );
}
///////////////////// playlist container callbacks
void __stdcall SpotifyGuiController::playlist_added(sp_playlistcontainer *pc, sp_playlist *playlist, int position, void *userdata)
{
	SpotifyGuiController *instance = (SpotifyGuiController *)userdata;
	SpotifyUserData *sp_data = (SpotifyUserData *)instance->spotify_userdata;

	if (instance->logWin) instance->logWin->addRow(TEXT("Playlist Received...."));

	//aggiungo la callback per la playlist
	sp_playlist_add_callbacks(playlist, sp_data->playlist_cb, instance);
}
/**
 * Callback from libspotify, telling us a playlist was added to the playlist container.
 *
 * We add our playlist callbacks to the newly added playlist.
 *
 * @param  pc            The playlist container handle
 * @param  pl            The playlist handle
 * @param  position      Index of the added playlist
 * @param  userdata      The opaque pointer
 */
static void playlist_added(sp_playlistcontainer *pc, sp_playlist *pl,
                           int position, void *userdata)
{
	sp_playlist_add_callbacks(pl, &pl_callbacks, NULL);

	if (!strcasecmp(sp_playlist_name(pl), g_listname)) {
		g_jukeboxlist = pl;
		try_jukebox_start();
	}
}
Beispiel #8
0
void start_playlist(char *uri)
{
	printf("Start playlist: %s\n", uri);
	sp_link *link = sp_link_create_from_string(uri);
	sp_playlist *pl = sp_playlist_create(g_sess, link);
	sp_playlist_add_callbacks(pl, &pl_callbacks, NULL);
	sprintf(g_last_playlist_name, sp_playlist_name(pl));
	// hardware_banner(sp_playlist_name(pl), 200);
	g_jukeboxlist = pl;
	try_jukebox_start();
}
Beispiel #9
0
// Creates a playlist resource object
static php_spotify_playlist * playlist_resource_create(php_spotify_session *session, sp_playlist *playlist) {

	php_spotify_playlist * resource = emalloc(sizeof(php_spotify_playlist));

	resource->session  = session;
	resource->playlist = playlist;

	sp_playlist_add_callbacks(playlist, &callbacks, resource);

	return resource;
}
Beispiel #10
0
static struct playlist_handler *register_playlist_callbacks(
    sp_playlist *playlist,
    struct evhttp_request *request,
    handle_playlist_fn callback,
    sp_playlist_callbacks *playlist_callbacks,
    void *userdata) {
  struct playlist_handler *handler = malloc(sizeof (struct playlist_handler));
  handler->request = request;
  handler->callback = callback;
  handler->playlist_callbacks = playlist_callbacks;
  handler->userdata = userdata;
  sp_playlist_add_callbacks(playlist, handler->playlist_callbacks, handler);
  return handler;
}
void Spotify::changeCurrentPlaylist()
{
    sp_error err;
    sp_playlist * playlist;

    if (currentPlaylistIdx < 0) {
        return;
    }

    sp_playlistcontainer * pc = sp_session_playlistcontainer(sp);
    if (currentPlaylistIdx >= sp_playlistcontainer_num_playlists(pc)) {
        return;
    }

    switch (sp_playlistcontainer_playlist_type(pc, currentPlaylistIdx)) {
    case SP_PLAYLIST_TYPE_PLAYLIST:
        playlist = sp_playlistcontainer_playlist(pc, currentPlaylistIdx);
        if (!playlist) {
            fprintf(stderr, "Spotify: failed to get playlist\n");
            break;
        }

        err = sp_playlist_add_callbacks(playlist, Spotify_Wrapper::playlistCallbacks(), NULL);
        if (err != SP_ERROR_OK) {
            fprintf(stderr, "Spotify: failed to add callbacks to playlist: %s\n",
                    sp_error_message(err));
        }

        if (currentPlaylist) {
            sp_playlist_remove_callbacks(currentPlaylist, Spotify_Wrapper::playlistCallbacks(), NULL);
            sp_playlist_release(currentPlaylist);
        }
        currentPlaylist = playlist;
        sp_playlist_add_ref(currentPlaylist);

        fprintf(stderr, "Spotify: switched to playlist %s\n",
                sp_playlist_name(currentPlaylist));

        tryLoadPlaylist();
        break;

    default:
        fprintf(stderr, "Spotify: Tried to load a playlist that wasn't a playlist\n");
        currentPlaylistIdx = -1;
        break;
    }
}
Beispiel #12
0
bool XplodifyPlaylist::load(sp_playlist * pl) {
    if(!pl) {
        return false;
    }

    m_playlist = pl;
    sp_playlist_add_callbacks(pl, const_cast<sp_playlist_callbacks *>(&cbs), this);

    if(!sp_playlist_is_loaded(pl))
    {
        m_loading = true;
    } else {
        m_loading = false; //already loaded.
        load_tracks();
    }

    return true;
}
Beispiel #13
0
/**
 * This callback is called when an attempt to login has succeeded or failed.
 *
 * @sa sp_session_callbacks#logged_in
 */
static void logged_in(sp_session *session, sp_error error)
{
	sp_user *me;
	const char *my_name;

	if (SP_ERROR_OK != error) {
		fprintf(stderr, "failed to log in to Spotify: %s\n",
		                sp_error_message(error));
		sp_session_release(session);
		exit(4);
	}

	// Let us print the nice message...
	me = sp_session_user(session);
	my_name = (sp_user_is_loaded(me) ? sp_user_display_name(me) : sp_user_canonical_name(me));

	fprintf(stderr, "Logged in to Spotify as user %s\n", my_name);
    sp_playlist *pl = sp_playlist_create(session, sp_link_create_from_string("spotify:user:devnevyn:playlist:44ZXlJstDZrwuQvWPOo7KX"));
    empty_callbacks.playlist_state_changed = foo;
    sp_playlist_add_callbacks(pl, &empty_callbacks, NULL);
}
Beispiel #14
0
static PyObject *Playlist__add_callback(Playlist *self, PyObject *args, sp_playlist_callbacks pl_callbacks) {
    PyObject *callback;
    PyObject *userdata = NULL;
    playlist_callback_trampoline *tramp;
    if(!PyArg_ParseTuple(args, "O|O", &callback, &userdata))
        return NULL;
    if (userdata == NULL) {
        userdata = (PyObject *)Py_None;
        Py_INCREF(Py_None);
    }
    Py_INCREF(callback);
    Py_INCREF(userdata);
    tramp = malloc(sizeof(playlist_callback_trampoline));
    tramp->userdata = userdata;
    tramp->callback = callback;
    Py_BEGIN_ALLOW_THREADS
    sp_playlist_add_callbacks(self->_playlist, &pl_callbacks, tramp);
    Py_END_ALLOW_THREADS
    Py_INCREF(Py_None);
    return Py_None;
}
Beispiel #15
0
/**
 * This callback is called when an attempt to login has succeeded or failed.
 *
 * @sa sp_session_callbacks#logged_in
 */
static void logged_in ( sp_session *sess, sp_error error )
{
    sp_playlistcontainer *pc = sp_session_playlistcontainer ( sess );
    int i;

    if ( SP_ERROR_OK != error )
    {
        fprintf ( stderr, "jahspotify: Login failed: %s\n", sp_error_message ( error ) );
        exit ( 2 );
    }

    fprintf ( stderr, "jahspotify: Login Success: %d\n", sp_playlistcontainer_num_playlists(pc));

    for (i = 0; i < sp_playlistcontainer_num_playlists(pc); ++i) {
        sp_playlist *pl = sp_playlistcontainer_playlist(pc, i);

        sp_playlist_add_callbacks(pl, &pl_callbacks, NULL);
    }

    signalLoggedIn();

}
void SpotifyGuiController::RefreshPlaylistTracks ( sp_playlist *plist )
{
	if ( plist && plist != selected_playlist )
	{

		if ( trackTree ) trackTree->removeAllItem();

		SpotifyUserData *sp_data = (SpotifyUserData *)spotify_userdata;

		//ho la playlist, carico le tracce
		sp_playlist_add_callbacks(plist, sp_data->playlist_cb, this);

		if ( sp_playlist_is_loaded(plist) )
		{
			//aggiungo tracce
			int n_tracks = sp_playlist_num_tracks(plist);

			for ( int nt = 0 ; nt < n_tracks ; nt++ )
			{
				sp_track *track = sp_playlist_track(plist, nt);

				if ( track && sp_track_is_loaded(track) )
				{
					if ( trackTree )
					{
						TCHAR trackname[1001] = {0};
						memset(trackname, 0, sizeof(TCHAR)*1001);

						_sntprintf_s(trackname, 1000, TEXT("%hs"), sp_track_name(track));
						trackTree->addItemAsLast(NULL, trackname, track, 0);
					}
				}
			}
		}

	}

}
Beispiel #17
0
void browse_playlist(sp_playlist *pl)
{
	playlist_browse = pl;
	sp_playlist_add_callbacks(playlist_browse, &pl_callbacks, NULL);
	playlist_browse_try();
}
Beispiel #18
0
static void playlist_added(sp_playlistcontainer *pc, sp_playlist *pl,
                           int position, void *userdata) 
{
//	printf("playlist_added: %s\n", sp_playlist_name(pl));
	sp_playlist_add_callbacks(pl, &pl_callbacks, NULL);
}