/** * 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 SP_CALLCONV playlist_added(sp_playlistcontainer *pc, sp_playlist *pl, int position, void *userdata) { sp_playlist_add_callbacks(pl, &pl_callbacks, NULL); printf("playlist loaded: %s\n", sp_playlist_name(pl)); if (!strcasecmp(sp_playlist_name(pl), g_listname)) { g_jukeboxlist = pl; try_jukebox_start(); } }
/** * Callback from libspotify, telling us a playlist was removed from the playlist container. * * This is the place to remove our playlist callbacks. * * @param pc The playlist container handle * @param pl The playlist handle * @param position Index of the removed playlist * @param userdata The opaque pointer */ static void playlist_removed ( sp_playlistcontainer *pc, sp_playlist *pl, int position, void *userdata ) { const char *name = sp_playlist_name(pl); // fprintf(stderr,"jahspotify: playlist removed: %s\n ",name); sp_playlist_remove_callbacks ( pl, &pl_callbacks, NULL ); }
PHP_METHOD(SpotifyPlaylist, getName) { zval *object = getThis(); spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(object TSRMLS_CC); RETURN_STRING(sp_playlist_name(p->playlist), 1); }
void SP_CALLCONV playlist_renamed(sp_playlist *pl, void *userdata) { sp_playlistcontainer *pc = sp_session_playlistcontainer(session); int num = sp_playlistcontainer_num_playlists(pc); int pos; MLTREEITEMINFO treeItemInfo; UINT_PTR treeId, treeHandle; /* Find position of renamed playlist in the playlist container */ for(pos = 0; pos < num; pos++) if(sp_playlistcontainer_playlist(pc, pos) == pl) break; if(pos == num) { DSFYDEBUG("WTF, did not find playlist %p in container!\n", pl); return; } /* Get tree ID so we can get the handle */ treeId = tpGetTreeId(pos); treeHandle = SendMessage(hwndLibraryParent, WM_ML_IPC, (WPARAM)treeId, ML_IPC_TREEITEM_GETHANDLE); /* Create request to update the item */ memset(&treeItemInfo, 0, sizeof(MLTREEITEMINFO)); treeItemInfo.handle = treeHandle; treeItemInfo.mask = MLTI_TEXT; treeItemInfo.item.size = sizeof(MLTREEITEM); treeItemInfo.item.title = (char *)sp_playlist_name(pl); /* Submit request */ SendMessage(hwndLibraryParent, WM_ML_IPC, (WPARAM)&treeItemInfo, ML_IPC_TREEITEM_SETINFO); }
/** * 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); } }
int cmd_playlist(int argc, char **argv) { int index, i; sp_track *track; sp_playlist *playlist; sp_playlistcontainer *pc = sp_session_playlistcontainer(g_session); if (argc < 1) { printf("playlist [playlist index]\n"); return 0; } index = atoi(argv[1]); if (index < 0 || index > sp_playlistcontainer_num_playlists(pc)) { printf("invalid index\n"); return 0; } playlist = sp_playlistcontainer_playlist(pc, index); printf("Playlist %s by %s%s%s\n", sp_playlist_name(playlist), sp_user_display_name(sp_playlist_owner(playlist)), sp_playlist_is_collaborative(playlist) ? " (collaborative)" : "", sp_playlist_has_pending_changes(playlist) ? " with pending changes" : "" ); for (i = 0; i < sp_playlist_num_tracks(playlist); ++i) { track = sp_playlist_track(playlist, i); printf("%d. %c %s%s %s\n", i, sp_track_is_starred(g_session, track) ? '*' : ' ', sp_track_is_local(g_session, track) ? "local" : " ", sp_track_is_autolinked(g_session, track) ? "autolinked" : " ", sp_track_name(track)); } return 1; }
/** * 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 ); }
//when we put in Exceptions this will be a lot cleaner. std::string XplodifyPlaylist::get_name(bool cache) { if(!m_playlist) { return std::string(""); } if(cache && is_cached()) { return m_name; } return std::string(sp_playlist_name(m_playlist)); }
void SP_CALLCONV pl_tracks_added(sp_playlist *pl, const sp_track **tracks, int num_tracks, int position, void *userdata) { DSFYDEBUG("Playlist '%s': %d tracks added\n", sp_playlist_name(pl), num_tracks); /* * FIXME: Actually do something here ;) * GetDlgItem(.., IDC_LIST), issue a ListView_RedrawIterms() and handle * WM_NOTIFY messages in the ListView's parent window to update its entries * */ }
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(); }
void Spotify::compileNewListOfPlaylists() { sp_playlistcontainer * pc = sp_session_playlistcontainer(sp); int numPlaylists = sp_playlistcontainer_num_playlists(pc); QStringList names; for (int idx = 0; idx < numPlaylists; ++idx) { sp_playlist *pl = sp_playlistcontainer_playlist(pc, idx); names << QString::fromLocal8Bit(sp_playlist_name(pl)); } emit playlistsUpdated(names); }
static void playlist_update_in_progress ( sp_playlist *pl, bool done, void *userdata ) { const char *name = sp_playlist_name ( pl ); char *playListlinkStr; char *trackLinkStr; sp_link *link; int trackCounter; // fprintf ( stderr,"jahspotify: playlist update in progress: %s (done: %s)\n",name, (done ? "yes" : "no")); if (done) { link = sp_link_create_from_playlist(pl); if (link) { playListlinkStr = malloc ( sizeof ( char ) * ( 100 ) ); sp_link_as_string(link,playListlinkStr,100); sp_link_release(link); signalPlaylistSeen(name,playListlinkStr); } //sp_link_release(link); // int numTracks = sp_playlist_num_tracks(pl); // fprintf ( stderr,"jahspotify: playlist: %s num tracks: %d id: %s\n",name,numTracks,playListlinkStr); // for (trackCounter = 0 ; trackCounter < numTracks; trackCounter++) // { // sp_track *track = sp_playlist_track(pl,trackCounter); // if (sp_track_is_loaded(track)) // { // link = sp_link_create_from_track(track,0); // trackLinkStr = malloc ( sizeof ( char ) * ( 100 ) ); // sp_link_as_string(link,trackLinkStr,100); // fprintf ( stderr,"jahspotify: track name: %s track id: %s\n",sp_track_name(track),trackLinkStr); // sp_link_release(link); // if (trackLinkStr) (trackLinkStr); // } // sp_track_release(track); // } // // if (playListlinkStr) free(playListlinkStr); // } } }
// ---------------------------------------------------------------------------- // bool DMX_PLAYER_API GetPlaylistName( LPCSTR playlist_link, LPSTR buffer, size_t buffer_length ) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); sp_playlist* playlist = theApp.m_spotify.linkToPlaylist( playlist_link ); if ( playlist == NULL ) return false; LPCSTR name = sp_playlist_name( playlist ); if ( name == NULL || strlen(name)+1 > buffer_length ) return false; errno_t err = strncpy_s( buffer, buffer_length, name, strlen(name) ); return err == 0; }
/** * Callback from libspotify. Something renamed the playlist. * * @param pl The playlist handle * @param userdata The opaque pointer */ static void playlist_renamed(sp_playlist *pl, void *userdata) { const char *name = sp_playlist_name(pl); if (!strcasecmp(name, g_listname)) { g_jukeboxlist = pl; g_track_index = 0; try_jukebox_start(); } else if (g_jukeboxlist == pl) { printf("jukebox: current playlist renamed to \"%s\".\n", name); g_jukeboxlist = NULL; g_currenttrack = NULL; sp_session_player_unload(g_sess); } }
void SpotifyGuiController::AddPlaylist( sp_playlist *plist) { if (plist ) { //aggiungo if (sp_playlist_is_loaded(plist) && playlistTree) { TCHAR plist_name[1001] = { 0 }; _sntprintf_s(plist_name, 1000, TEXT("%hs"), sp_playlist_name(plist)); playlistTree->addItemAsLast(NULL, plist_name, plist, 0); //sp_playlist_add_ref(plist); } } }
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; } }
static bool validate_complete_load() { if (g_list_container == NULL) { return false; } sp_playlistcontainer *list_container = g_list_container; int pl_count = sp_playlistcontainer_num_playlists(list_container); int i=0; for(; i < pl_count; i++) { sp_playlist *l = sp_playlistcontainer_playlist(list_container, i); sp_playlist_type type = sp_playlistcontainer_playlist_type(list_container, i); if (type == SP_PLAYLIST_TYPE_PLAYLIST && !sp_playlist_is_loaded(l)) { return false; } } sp_playlist *source_list = NULL; i=0; for(; i < pl_count; i++) { sp_playlist *l = sp_playlistcontainer_playlist(list_container, i); const char* pname = sp_playlist_name(l); if (strcmp(pname, playlist_name) == 0) { source_list = l; break; } } if (source_list == NULL) { fprintf(stderr, "Cannot find source list: %s\n", playlist_name); exit(1); } int nt = sp_playlist_num_tracks(source_list); i=0; for(; i < nt; i++) { sp_track *t = sp_playlist_track(source_list, i); sp_artist *a = sp_track_artist(t,0); // get first artist on track because I am lazy sp_album *al = sp_track_album(t); if (al == NULL || a == NULL) { return false; } } return true; }
static sp_playlist *find_album_playlist(sp_playlistcontainer *list_container, int *spiffify_start_index, int spiffify_end_index, sp_album *al) { if (al == NULL) { return NULL; } int j=*spiffify_start_index; sp_artist *a = sp_album_artist(al); const char *artist = sp_artist_name(a); int artist_end = 0; sp_uint64 artist_folder_id = 0; for(; j < spiffify_end_index; j++) { sp_playlist *p = sp_playlistcontainer_playlist(list_container, j); if (p == NULL) { continue; } sp_playlist_type type = sp_playlistcontainer_playlist_type(list_container,j); if (type == SP_PLAYLIST_TYPE_START_FOLDER) { char folder_name[256]; sp_error error = sp_playlistcontainer_playlist_folder_name(list_container, j, folder_name, 255); if (strcmp(folder_name, artist) == 0) { artist_folder_id = sp_playlistcontainer_playlist_folder_id(list_container, j); } } else if (type == SP_PLAYLIST_TYPE_END_FOLDER) { if (artist_folder_id == sp_playlistcontainer_playlist_folder_id(list_container, j)) { artist_end = j; } } const char *plname = sp_playlist_name(p); if (plname != NULL) { const char *alname = sp_album_name(al); if (strcmp(plname, alname) == 0) { return p; } } } // in the case where we don't yet have the playlist for this album and we are about to create it, send back the end of this artist folder if (artist_end != 0) { *spiffify_start_index = artist_end-1; } return NULL; }
int cmd_playlists(int argc, char **argv) { sp_playlistcontainer *pc = sp_session_playlistcontainer(g_session); int i, j, level = 0; sp_playlist *pl; char name[200]; printf("%d entries in the container\n", sp_playlistcontainer_num_playlists(pc)); for (i = 0; i < sp_playlistcontainer_num_playlists(pc); ++i) { switch (sp_playlistcontainer_playlist_type(pc, i)) { case SP_PLAYLIST_TYPE_PLAYLIST: printf("%d. ", i); for (j = level; j; --j) printf("\t"); pl = sp_playlistcontainer_playlist(pc, i); printf("%s", sp_playlist_name(pl)); if(subscriptions_updated) printf(" (%d subscribers)", sp_playlist_num_subscribers(pl)); printf("\n"); break; case SP_PLAYLIST_TYPE_START_FOLDER: printf("%d. ", i); for (j = level; j; --j) printf("\t"); sp_playlistcontainer_playlist_folder_name(pc, i, name, sizeof(name)); printf("Folder: %s with id %llu\n", name, sp_playlistcontainer_playlist_folder_id(pc, i)); level++; break; case SP_PLAYLIST_TYPE_END_FOLDER: level--; printf("%d. ", i); for (j = level; j; --j) printf("\t"); printf("End folder with id %llu\n", sp_playlistcontainer_playlist_folder_id(pc, i)); break; case SP_PLAYLIST_TYPE_PLACEHOLDER: printf("%d. Placeholder", i); break; } } return 1; }
void SpotWorker::emitLoggedInSignal(sp_session *session, sp_error error) { if (SP_ERROR_OK != error) { fprintf(stderr, "SpotWorker: Login failed: %s\n", sp_error_message(error)); } else{ printf("SpotWorker: Successfully logged in\n"); emit loggedIn(session, error); sp_playlistcontainer *playlists = sp_session_playlistcontainer(session); void * userdata = NULL; sp_playlistcontainer_add_callbacks(playlists, &pc_callbacks, userdata); int listCount = sp_playlistcontainer_num_playlists(playlists); printf("%d playlists discovered\n", sp_playlistcontainer_num_playlists(playlists)); if(listCount > 0) emit playlistAdded(playlists); for (int i = 0; i < listCount && i < 10; ++i) { sp_playlist *pl = sp_playlistcontainer_playlist(playlists, i); //TODO: register playback callback //sp_playlist_add_callbacks(pl, &pl_callbacks, NULL); if (sp_playlist_is_loaded(pl)){ DEBUG printf("Playlist found: %s (%i tracks)\n", sp_playlist_name(pl), sp_playlist_num_tracks(pl)); } } DEBUG { if (listCount > 10) printf("...and %d more.\n", listCount-10); } } }
void Spotify::tryLoadPlaylist() { if ((currentPlaylistIdx < 0) || (currentPlaylist == 0)) { return; } if (sp_playlist_is_loaded(currentPlaylist)) { QList<SpotifyTrackInfo> tracks; int numTracks = sp_playlist_num_tracks(currentPlaylist); for (int idx = 0; idx < numTracks; ++idx) { sp_track * track = sp_playlist_track(currentPlaylist, idx); if (!track) { fprintf(stderr, "Spotify: failed to get track #%d\n", idx + 1); continue; } QString name(sp_track_name(track)); if (name.isEmpty()) { fprintf(stderr, "Spotify: got empty track name\n"); continue; } SpotifyTrackInfo info; info.name = name; info.URI = uriFromTrack(track); if (info.URI.isEmpty()) { continue; } tracks.append(info); } emit currentPlaylistUpdated(tracks); fprintf(stderr, "Spotify: loaded playlist %s (%d tracks)\n", sp_playlist_name(currentPlaylist), tracks.size()); } }
int cmd_set_autolink(int argc, char **argv) { int index; bool autolink; sp_playlist *playlist; sp_playlistcontainer *pc = sp_session_playlistcontainer(g_session); if (argc < 2) { printf("set autolink [playlist index] [0/1]\n"); return 0; } index = atoi(argv[1]); autolink = atoi(argv[2]); if (index < 0 || index > sp_playlistcontainer_num_playlists(pc)) { printf("invalid index\n"); return 0; } playlist = sp_playlistcontainer_playlist(pc, index); sp_playlist_set_autolink_tracks(playlist, !!autolink); printf("Set autolinking to %s on playlist %s\n", autolink ? "true": "false", sp_playlist_name(playlist)); return 1; }
ListResponse<PlaylistInfo*>* SpotifyPlaylistContainer::listPlaylists( PlaylistTask* task) { ListResponse<PlaylistInfo*>* response = new ListResponse<PlaylistInfo*>(); response->setListType(ListTypePlaylist); CommandInfo info = task->getCommandInfo(); bool sendName = ((info.ListFlags & Name) == Name); bool sendNumTracks = ((info.ListFlags & NumTracks) == NumTracks); bool sendDescription = ((info.ListFlags & Description) == Description); int numPlaylists = sp_playlistcontainer_num_playlists(playlistContainer); for (int i = 0; i < numPlaylists; i++) { if (sp_playlistcontainer_playlist_type(playlistContainer, i) == SP_PLAYLIST_TYPE_PLAYLIST) { sp_playlist* playlist = sp_playlistcontainer_playlist( playlistContainer, i); const char* name = sp_playlist_name(playlist); if (!(name[0] == '_' && name[1] == '_')) { PlaylistInfo* playlistInfo = new PlaylistInfo(); playlistInfo->id = i; if (sendName) { playlistInfo->name = name; } if (sendNumTracks) { playlistInfo->numTracks = sp_playlist_num_tracks(playlist); } if (sendDescription) { playlistInfo->description = sp_playlist_get_description( playlist); } response->addMember(playlistInfo); } } } return response; }
/** * Move playlists */ int sort_playlists(sp_session *session) { sp_playlistcontainer *pc = sp_session_playlistcontainer(session); sp_playlist_type playlist_type; int i, not_loaded = 0, num_playlists = 0; int *reorder; sp_playlist *pl; node *items, *parent, *previous; #ifdef TESTING playlist_item *faux_playlist; #endif num_playlists = sp_playlistcontainer_num_playlists(pc); items = previous = parent = NULL; #ifdef TESTING faux_playlist = (playlist_item*) malloc(sizeof(playlist_item) * num_playlists); #endif printf("Reordering %d playlists and playlist folders\n", num_playlists); for (i = 0; i < num_playlists; ++i) { playlist_type = sp_playlistcontainer_playlist_type(pc, i); switch (playlist_type) { case SP_PLAYLIST_TYPE_PLAYLIST: pl = sp_playlistcontainer_playlist(pc, i); if (!sp_playlist_is_loaded(pl)) { not_loaded++; } else { previous = create_node(previous, parent, create_playlist_item(i, sp_playlist_name(pl))); if (items == NULL) { items = previous; } } #ifdef TESTING faux_playlist[i].index = -1; faux_playlist[i].name = strdup(sp_playlist_name(pl)); #endif break; case SP_PLAYLIST_TYPE_START_FOLDER: parent = create_node(previous, parent, create_playlist_item(i, sp_playlistcontainer_playlist_folder_name(pc, i))); previous = NULL; if (items == NULL) { items = parent; } #ifdef TESTING faux_playlist[i].index = sp_playlistcontainer_playlist_folder_id(pc, i); faux_playlist[i].name = strdup(sp_playlistcontainer_playlist_folder_name(pc, i)); #endif break; case SP_PLAYLIST_TYPE_END_FOLDER: previous = parent; previous->item->end_index = i; parent = parent->parent; #ifdef TESTING faux_playlist[i].index = sp_playlistcontainer_playlist_folder_id(pc, i); faux_playlist[i].name = NULL; #endif break; case SP_PLAYLIST_TYPE_PLACEHOLDER: #ifdef TESTING printf("%d. Placeholder", i); faux_playlist[i].index = -1; faux_playlist[i].name = NULL; #endif break; } } if(not_loaded > 0) { printf("ERROR: %d playlists could not be loaded\n", not_loaded); return 1; } if(items != NULL) { items = sort_list(items); #ifdef TESTING print_list(items); #endif reorder = (int *) malloc(sizeof(int) * num_playlists); flatten_list(items, reorder); for(i = 0; i < num_playlists; ++i) { printf("."); if(i != reorder[i]) { #ifdef TESTING printf("Moving item at %d -> %d\n", reorder[i], i); move_playlist(faux_playlist, num_playlists, reorder[i], i); #else sp_playlistcontainer_move_playlist(pc, reorder[i], i); #endif recalculate_indexes(reorder, num_playlists, i); } } printf("\ndone\n"); free(reorder); free_list(items); } #ifdef TESTING for(i = 0; i < num_playlists; ++i) { if(faux_playlist[i].name != NULL) { printf(" -- %s (%d)\n", faux_playlist[i].name, faux_playlist[i].index); free((void*)faux_playlist[i].name); } else { printf(" -- %d\n", faux_playlist[i].index); } } free(faux_playlist); #endif return 1; }
static bool spiffify() { if (!validate_complete_load()) { return false; } sp_playlistcontainer *list_container = g_list_container; // check to see if all playlists have been loaded int pl_count = sp_playlistcontainer_num_playlists(list_container); int i=0; sp_playlist *source_list = NULL; sp_playlist *spiffify_list = NULL; char folder_name[256]; int spiffify_start_index = -1; int spiffify_end_index = -1; sp_uint64 spiffify_folder_id = -1; i=0; for(; i < pl_count; i++) { sp_playlist *l = sp_playlistcontainer_playlist(list_container, i); const char* pname = sp_playlist_name(l); if (strcmp(pname, playlist_name) == 0) { source_list = l; } sp_playlist_type type = sp_playlistcontainer_playlist_type(list_container, i); if (type == SP_PLAYLIST_TYPE_START_FOLDER) { sp_error error = sp_playlistcontainer_playlist_folder_name(list_container, i, folder_name, 256); if (error == SP_ERROR_OK) { if (strcmp(folder_name, SPIFFIFY_PLAYLIST_NAME) == 0) { spiffify_list = l; spiffify_start_index = i; spiffify_folder_id = sp_playlistcontainer_playlist_folder_id(list_container, i); } } } else if (type == SP_PLAYLIST_TYPE_END_FOLDER) { sp_uint64 id = sp_playlistcontainer_playlist_folder_id(list_container, i); if (id == spiffify_folder_id) { spiffify_end_index = i; } } } if (source_list == NULL) { fprintf(stderr, "Cannot find source list: %s\n", playlist_name); exit(1); } if (spiffify_list != NULL && spiffify_start_index != -1) { // smoke the list and start over every time.. it's just not worth the effort of inserting changes. int x=spiffify_end_index; for(; x >= spiffify_start_index; x--) { sp_playlistcontainer_remove_playlist(list_container, x); } spiffify_list = NULL; spiffify_start_index = -1; spiffify_end_index = -1; } pl_count = sp_playlistcontainer_num_playlists(list_container); // reset count. if (spiffify_list == NULL) { // make the Spiffify list for this user; sp_error error = sp_playlistcontainer_add_folder(list_container, pl_count, SPIFFIFY_PLAYLIST_NAME); if (error == SP_ERROR_OK) { spiffify_list = sp_playlistcontainer_playlist(list_container, pl_count); spiffify_start_index = pl_count; spiffify_end_index = spiffify_start_index+1; } if (spiffify_list == NULL) { fprintf(stderr, "Cannot create '%s' playlist\n", SPIFFIFY_PLAYLIST_NAME); exit(1); } } // iterate the source playlist int nt = sp_playlist_num_tracks(source_list); // allocate storage for tracks sp_track **tracks = (sp_track **) malloc(nt * sizeof(sp_track *)); i=0; for(; i < nt; i++) { sp_track *t = sp_playlist_track(source_list, i); tracks[i] = t; // store in the array } // :) mergesort(tracks, nt, sizeof(sp_track *), &compare_tracks); i=0; for(; i < nt; i++) { sp_track *t = tracks[i]; //sp_playlist_track(source_list, i); sp_artist *a = sp_track_artist(t,0); // get first artist on track because I am lazy // find artist folder inside our spiffify list bool haveartist = false; int j=spiffify_start_index; char artist[256]; if (a != NULL) { strcpy(artist, sp_artist_name(a)); } else { strcpy(artist, "Unknown Artist"); } for(; j < spiffify_end_index; j++) { sp_error error = sp_playlistcontainer_playlist_folder_name(list_container, j, folder_name, 256); if (strcmp(artist, folder_name) == 0) { haveartist = true; break; } } sp_album *al = sp_track_album(t); while (al == NULL) { printf("Cannot find album or it's not loaded.. forcing an event loop\n"); return false; } if (!haveartist) { int artist_pos = spiffify_end_index; sp_playlistcontainer_add_folder(list_container, artist_pos, artist); spiffify_end_index+=2; // a folder adds 2 indexes. pl_count = sp_playlistcontainer_num_playlists(list_container); sp_playlist* album = sp_playlistcontainer_add_new_playlist(list_container, sp_album_name(al)); sp_playlist_add_tracks(album, &t, 1, 0, session); sp_playlistcontainer_move_playlist(list_container, pl_count, artist_pos+1, false); spiffify_end_index++; // one more for the album. } else { int artist_pos = j; sp_playlist *albumpl = find_album_playlist(list_container, &artist_pos, spiffify_end_index, al); if (albumpl == NULL) { pl_count = sp_playlistcontainer_num_playlists(list_container); albumpl = sp_playlistcontainer_add_new_playlist(list_container, sp_album_name(al)); sp_playlistcontainer_move_playlist(list_container, pl_count, artist_pos+1, false); spiffify_end_index++; // one more for the album. } sp_playlist_add_tracks(albumpl, &t, 1, 0, session); } } free(tracks); return true; }
void check_playlist_status(sp_playlist *playlist) { printf("Playlist needs to load. Will cache on HD, so you won't need to wait this long again\n"); printf("waiting for playlist %s\n", sp_playlist_name(playlist)); printf("number of tracks %d\n", sp_playlist_num_tracks(playlist)); }
static void pl_renamed(sp_playlist *pl, void *userdata) { printf("\tList name: %s\n", sp_playlist_name(pl)); }
PHP_METHOD(SpotifyPlaylist, __toString) { spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); RETURN_STRING(sp_playlist_name(p->playlist), 1); }
jobject createJPlaylist(JNIEnv *env, sp_playlist *playlist) { jclass jClass; jobject playlistInstance; jmethodID jMethod; jClass = (*env)->FindClass(env, "jahspotify/media/Playlist"); if (jClass == NULL) { fprintf(stderr,"jahspotify::createJPlaylist: could not load jahnotify.media.Playlist\n"); return NULL; } playlistInstance = (*env)->AllocObject(env,jClass); if (!playlistInstance) { fprintf(stderr,"jahspotify::createJPlaylist: could not create instance of jahspotify.media.Playlistt\n"); return NULL; } sp_link *playlistLink = sp_link_create_from_playlist(playlist); if (playlistLink) { jobject playlistJLink = createJLinkInstance(env,playlistLink); setObjectObjectField(env,playlistInstance,"id","Ljahspotify/media/Link;",playlistJLink); sp_link_release(playlistLink); } setObjectStringField(env,playlistInstance,"name",sp_playlist_name(playlist)); sp_user *owner = sp_playlist_owner(playlist); if (owner) { setObjectStringField(env,playlistInstance,"author",sp_user_display_name(owner)); sp_user_release(owner); } // Lookup the method now - saves us looking it up for each iteration of the loop jMethod = (*env)->GetMethodID(env,jClass,"addTrack","(Ljahspotify/media/Link;)V"); if (jMethod == NULL) { fprintf(stderr,"jahspotify::createJPlaylist: could not load method addTrack(track) on class Playlist\n"); return NULL; } int numTracks = sp_playlist_num_tracks(playlist); int trackCounter = 0; for (trackCounter = 0 ; trackCounter < numTracks; trackCounter++) { sp_track *track = sp_playlist_track(playlist,trackCounter); if (track) { sp_track_add_ref(track); sp_link *trackLink = sp_link_create_from_track(track, 0); if (trackLink) { sp_link_add_ref(trackLink); jobject trackJLink = createJLinkInstance(env,trackLink); // Add it to the playlist (*env)->CallVoidMethod(env,playlistInstance,jMethod,trackJLink); sp_link_release(trackLink); } sp_track_release(track); } } return playlistInstance; }
json_t *playlist_to_json(sp_playlist *playlist, json_t *object) { assert(sp_playlist_is_loaded(playlist)); // Owner sp_user *owner = sp_playlist_owner(playlist); const char *username = sp_user_display_name(owner); sp_user_release(owner); json_object_set_new_nocheck(object, "creator", json_string_nocheck(username)); // URI size_t playlist_uri_len = strlen("spotify:user:"******":playlist:") + strlen("284on3DVWeAxWkgVuzZKGt"); char *playlist_uri = malloc(playlist_uri_len); if (playlist_uri == NULL) { return NULL; } sp_link *playlist_link = sp_link_create_from_playlist(playlist); sp_link_as_string(playlist_link, playlist_uri, playlist_uri_len); sp_link_release(playlist_link); json_object_set_new(object, "uri", json_string_nocheck(playlist_uri)); free(playlist_uri); // Title const char *title = sp_playlist_name(playlist); json_object_set_new(object, "title", json_string_nocheck(title)); // Collaborative playlist_to_json_set_collaborative(playlist, object); // Description const char *description = sp_playlist_get_description(playlist); if (description != NULL) { json_object_set_new(object, "description", json_string_nocheck(description)); } // Number of subscribers int num_subscribers = sp_playlist_num_subscribers(playlist); json_object_set_new(object, "subscriberCount", json_integer(num_subscribers)); // Tracks json_t *tracks = json_array(); json_object_set_new(object, "tracks", tracks); char track_uri[kTrackLinkLength]; for (int i = 0; i < sp_playlist_num_tracks(playlist); i++) { sp_track *track = sp_playlist_track(playlist, i); sp_link *track_link = sp_link_create_from_track(track, 0); sp_link_as_string(track_link, track_uri, kTrackLinkLength); json_array_append(tracks, json_string_nocheck(track_uri)); sp_link_release(track_link); } return object; }