Beispiel #1
0
/**
 * Callback for libspotify
 *
 * @param browse    The browse result object that is now done
 * @param userdata  The opaque pointer given to sp_artistbrowse_create()
 */
static void search_complete(sp_search *search, void *userdata)
{
  if (sp_search_error(search) == SP_ERROR_OK)
    print_search(search);
  else
    fprintf(stderr, "Failed to search: %s\n",
            sp_error_message(sp_search_error(search)));

  sp_search_release(search);
  cmd_done();
}
Beispiel #2
0
static void search_complete(sp_search *search, void *userdata)
{


        if (sp_search_error(search) == SP_ERROR_OK){
             get_search(search);
        }
        else cmd_sendresponse(put_error(400, sp_error_message(sp_search_error(search))), 400);

        sp_search_release(search);

        cmd_done();
}
void QSpotifySearch::populateResults(sp_search *search)
{
    if (search) {
        if (sp_search_error(search) != SP_ERROR_OK)
            return;

        populateAlbums(search);
        populateArtists(search);
        populatePlaylists(search);
        populateTracks(search);

        setDidYouMean(search);
    } else {
        m_albumResults->clear();
        m_artistResults->clear();
        m_playlistResults->clear();
        m_trackResults->clear();

        auto sourceList = QSpotifySession::instance()->playQueue()->m_sourceTrackList;
        if(sourceList == m_trackResults || sourceList == m_trackResultsPreview) {
            QSpotifySession::instance()->playQueue()->m_sourceTrackList = nullptr;
        }

        if (m_enablePreview) {
            m_albumResultsPreview->clear();
            m_artistResultsPreview->clear();
            m_playlistResultsPreview->clear();
            m_trackResultsPreview->clear();
        }
    }

    setBusy(false);

    emit resultsChanged();
}
Beispiel #4
0
static void SP_CALLCONV search_complete(sp_search *search, void *userdata) {
    printf("search complete!\n");
    fflush(stdout);
//    pthread_mutex_lock(&g_search_mutex);
    if (sp_search_error(search) == SP_ERROR_OK) {
//        pthread_cond_signal(&g_search_cond);
        *((int*) userdata) = 1;
    }
    else {
        printf("Failed to search: %s\n",
                sp_error_message(sp_search_error(search)));
        fflush(stdout);
    }

    char* rv = search_to_json(search);
    puts(rv);
//    pthread_mutex_unlock(&g_search_mutex);
}
Beispiel #5
0
static void search_complete(sp_search *result, void *userdata)
{
	sp_track *track;
	sp_artist *artist;
	int i;
	(void)userdata;

	if (sp_search_error(result) == SP_ERROR_OK) {
		for (i = 0; i < sp_search_num_tracks(result); ++i) {
			track = sp_search_track(result, i);
			artist = sp_track_artist(track, 0);
			printf("%d. %s - %s\n",
			       i, sp_track_name(track), sp_artist_name(artist));
		}
		fflush(stdout);

	} else {
		fprintf(stderr, "failed to search: %s",
				sp_error_message(sp_search_error(result)));
	}

	sp_search_release(result);
}
Beispiel #6
0
static void print_search_error(sp_search *search) {
    switch (sp_search_error(search)) {
        case SP_ERROR_OK:
            printf("ERROR_OK\n");
            break;
        case SP_ERROR_IS_LOADING:
            printf("ERROR_IS_LOADING\n");
            break;
        case SP_ERROR_OTHER_PERMANENT:
            printf("ERROR_OTHER_PERMANENT\n");
            break;
        case SP_ERROR_OTHER_TRANSIENT:
            printf("ERROR_OTHER_TRANSIENT\n");
            break;
        default:
            printf("I dunno what the problem is with search.\n");
    }
}
void SpotifyClient::SendSearchResponse(sp_search* result) {
  // Take the request out of the queue
  spotify_pb::SearchRequest req = pending_searches_.take(result);

  // Prepare the response
  spotify_pb::SpotifyMessage message;
  spotify_pb::SearchResponse* response = message.mutable_search_response();

  *response->mutable_request() = req;

  // Check for errors
  sp_error error = sp_search_error(result);
  if (error != SP_ERROR_OK) {
    response->set_error(sp_error_message(error));

    handler_->SendMessage(message);
    sp_search_release(result);
    return;
  }

  // Get the list of tracks from the search
  int count = sp_search_num_tracks(result);
  for (int i=0 ; i<count ; ++i) {
    sp_track* track = sp_search_track(result, i);
    ConvertTrack(track, response->add_result());
  }

  // Get the albums from the search.  All these should be resolved by now.
  QList<sp_albumbrowse*> browses = pending_search_album_browses_.take(result);
  foreach (sp_albumbrowse* browse, browses) {
    sp_album* album = sp_albumbrowse_album(browse);
    spotify_pb::Album* msg = response->add_album();

    ConvertAlbum(album, msg->mutable_metadata());
    ConvertAlbumBrowse(browse, msg->mutable_metadata());

    // Add all tracks
    const int tracks = sp_albumbrowse_num_tracks(browse);
    for (int i=0 ; i<tracks ; ++i) {
      ConvertTrack(sp_albumbrowse_track(browse, i), msg->add_track());
    }

    sp_albumbrowse_release(browse);
  }
bool QSpotifySearch::event(QEvent *e)
{
    if (e->type() == QEvent::User) {
        auto ev = static_cast<SearchResultEvent*>(e);
        if (ev) {
            if (auto search = ev->getSearch()) {
                g_mutex.lock();
                bool is_current = (m_sp_search == search);
                g_mutex.unlock();
                if (sp_search_error(search) == SP_ERROR_OK && is_current) {
                    if(ev->getPtr()) {
                        switch(ev->getPtr()->mType) {
                        case Albums:
                            populateAlbums(search);
                            break;
                        case Artists:
                            populateArtists(search);
                            break;
                        case Playlists:
                            populatePlaylists(search);
                            break;
                        case Tracks:
                            populateTracks(search);
                            break;
                        default:
                            populateResults(search);
                            break;
                        }
                    } else
                        populateResults(search);
                }
                clearSearch(search);
            }
        }
        setBusy(false);

        emit resultsChanged();

        e->accept();
        return true;
    }
    return QObject::event(e);
}
Beispiel #9
0
static void on_search_complete(sp_search *search, void *userdata)
{
	debug("callback: on_search_complete");
	sp_error error = sp_search_error(search);
	if (error != SP_ERROR_OK) {
		fprintf(stderr, "Error: %s\n", sp_error_message(error));
		exit(1);
	}

	int num_tracks = sp_search_num_tracks(search);
	if (num_tracks == 0) {
		fprintf(stderr, "Sorry, couldn't find that track. =/\n\n");
		sp_search_release(search);
		g_playing = 0;
		return;
	}

	sp_track *track = sp_search_track(search, 0);
	play((sp_session*)userdata, track);
	sp_search_release(search);
}
Beispiel #10
0
static void SP_CALLCONV search_complete(sp_search *search, void *userdata)
{
    debug("callback: search is complete");
	//g_menuChoice = -1;
	sp_error error = sp_search_error(search);
	if (error != SP_ERROR_OK) {
		fprintf(stderr, "Error: %s\n", sp_error_message(error));
		return;
	}

	int num_tracks = sp_search_num_tracks(search);
	if (num_tracks == 0) {
		printf("\nSorry, couldn't find that track.\n");
		return;
	}

	printf("Found track!\n");
	sp_track *track = sp_search_track(search, 0);
    queue_add_first(track);
    printf("Track added next in queue\n");
}
Beispiel #11
0
static PyObject *Results_error(Results *self) {
    return Py_BuildValue("i", sp_search_error(self->_search));
}
Beispiel #12
0
static void SP_CALLCONV search_complete(sp_search *search, void *userdata) {
    JNIEnv *env;
    jclass classLibspotify = find_class_from_native_thread(&env);
	string &qid = *static_cast<string*>(userdata);
    jstring j_qid = env->NewStringUTF(qid.c_str());
	bool success = (sp_search_error(search) == SP_ERROR_OK) ? true : false;
	int count = sp_search_num_tracks(search);
    jstring j_trackname;
    jstring j_trackuri;
    jstring j_albumname;
    jstring j_artistname;
	sp_track *track;
	for (int i=0;i< count;i++){
	    track = sp_search_track(search, i);
        if (track != 0 && sp_track_error(track) == SP_ERROR_OK){
            const char *temp = sp_track_name(track);
            if (temp != 0 && strlen(temp) != 0){
                j_trackname = env->NewStringUTF(temp);
            }
            int trackDuration = sp_track_duration(track);
            if (sp_track_error(track) != SP_ERROR_OK)
                log("sp_track_error: %s",sp_error_message(sp_track_error(track)));
            int trackDiscnumber = sp_track_disc(track);
            if (sp_track_error(track) != SP_ERROR_OK)
                log("sp_track_error: %s",sp_error_message(sp_track_error(track)));
            int trackIndex = sp_track_index(track);
            if (sp_track_error(track) != SP_ERROR_OK)
                log("sp_track_error: %s",sp_error_message(sp_track_error(track)));
            char buffer [64];
            sp_link *link = sp_link_create_from_track(track, 0);
            if (link != 0){
                sp_link_as_string(link, buffer, 64);
            }
            j_trackuri = env->NewStringUTF(buffer);
            sp_album *album = sp_track_album(track);
            if (sp_track_error(track) != SP_ERROR_OK)
                log("sp_track_error: %s",sp_error_message(sp_track_error(track)));
            int albumYear = 0;
            if (album != 0){
                temp = sp_album_name(album);
                albumYear = sp_album_year(album);
                if (temp != 0 && strlen(temp) != 0){
                    j_albumname = env->NewStringUTF(temp);
                }
            }
            sp_artist *artist = sp_track_artist(track,0);
            if (sp_track_error(track) != SP_ERROR_OK)
                log("sp_track_error: %s",sp_error_message(sp_track_error(track)));
            if (artist != 0){
                temp = sp_artist_name(artist);
                if (temp != 0 && strlen(temp) != 0){
                    j_artistname = env->NewStringUTF(temp);
                }
            }
            jmethodID methodIdAddResult = env->GetStaticMethodID(classLibspotify, "addResult",
                "(Ljava/lang/String;Ljava/lang/String;IIILjava/lang/String;Ljava/lang/String;ILjava/lang/String;)V");
            env->CallStaticVoidMethod(classLibspotify, methodIdAddResult, j_qid, j_trackname,
                trackDuration, trackDiscnumber, trackIndex, j_trackuri,
                j_albumname, albumYear, j_artistname);
            if (env->ExceptionCheck()) {
                env->ExceptionDescribe();
                env->ExceptionClear();
            }
            env->DeleteLocalRef(j_trackname);
            env->DeleteLocalRef(j_trackuri);
            env->DeleteLocalRef(j_artistname);
            env->DeleteLocalRef(j_albumname);
	        j_trackname = NULL;
	        j_trackuri = NULL;
	        j_artistname = NULL;
	        j_albumname = NULL;
        }
	}
    jmethodID methodIdOnResolved = env->GetStaticMethodID(classLibspotify, "onResolved",
	    "(Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V");
    jstring j_error = env->NewStringUTF(sp_error_message(sp_search_error(search)));
    jstring j_didyoumean = env->NewStringUTF(sp_search_did_you_mean(search));
    env->CallStaticVoidMethod(classLibspotify, methodIdOnResolved, j_qid, success, j_error,
        j_didyoumean);
    if (env->ExceptionCheck()) {
        env->ExceptionDescribe();
        env->ExceptionClear();
    }
	env->DeleteLocalRef(classLibspotify);
	env->DeleteLocalRef(j_qid);
	env->DeleteLocalRef(j_error);
	env->DeleteLocalRef(j_didyoumean);

    log("Finished resolving query:'%s', success'%s', track count:'%d', qid:'%s'", sp_search_query(search),
        (success?"true":"false"), count, qid.c_str());
    sp_search_release(search);
    delete &qid;
}