void QSpotifySearch::search(bool preview)
{
    setBusy(true);

    QMutexLocker lock(&g_mutex);
    if (!m_query.isEmpty()) {
        if(preview && m_enablePreview) {
            m_sp_search = sp_search_create(
                        QSpotifySession::instance()->m_sp_session,
                        m_query.toUtf8().constData(),
                        0, m_numPreviewItems, 0, m_numPreviewItems,
                        0, m_numPreviewItems, 0, m_numPreviewItems,
                        sp_search_type(m_searchType), callback_search_complete, nullptr);
        } else {
            m_sp_search = sp_search_create(
                        QSpotifySession::instance()->m_sp_session,
                        m_query.toUtf8().constData(),
                        0, m_tracksLimit, 0, m_albumsLimit,
                        0, m_artistsLimit, 0, m_playlistsLimit,
                        sp_search_type(m_searchType), callback_search_complete, nullptr);
        }
        g_searchObjects.insert(m_sp_search, this);
    } else {
        populateResults(nullptr);
    }
}
Exemplo n.º 2
0
static int spfs_mkdir(const char *path, mode_t mode)
{
  // only allow one "/", at the beginning
  if(strstr(path + 1, "/") != NULL) {
    errno = EIO;
    return -1;
  }

  folder_t *folder = calloc(1, sizeof(folder_t));
  strncpy(folder->name, path + 1, MAX_NAME_LENGTH);

  /*
    char search_string[MAX_NAME_LENGTH];
    memset(search_string, '\0', MAX_NAME_LENGTH * sizeof(char));
    strncpy(search_string, path + 1, strlen(path) - 5);
    printf("Spotify: Searching for %s\n", search_string);
    sp_search_create(session, search_string, 0, 1, 0, 0, 0, 0,
    &search_complete, (void *)folder);
  */

  printf("Spotify: Searching for %s\n", path + 1);

  sp_search_create(session, path + 1, 0, MAX_SEARCH_RESULTS, 0, 0, 0, 0,
                   &search_complete, (void *)folder);
  
  if(!folders) {
    folders = folder;
  }
  else {
    folder->next = folders;
    folders = folder;
  }

  return 0;
}
Exemplo n.º 3
0
void SpotWorker::performSearch(QString query)
{
    QByteArray qba = query.toUtf8();
    const char *needle = qba.data();
    printf("Requesting search. Query: %s\n", needle);
    const int track_offset = 0;
    const int track_count = 100;
    const int album_offset = 0;
    const int album_count = 100;
    const int artist_offset = 0;
    const int artist_count = 100;

    g_search = sp_search_create(currentSession,
                                needle,
                                track_offset,
                                track_count,
                                album_offset,
                                album_count,
                                artist_offset,
                                artist_count,
                                search_complete,
                                NULL);

    if (!g_search) {
        fprintf(stderr, "Clay Davis says: Sheeeet! Failed to start search!\n");
    }
}
Exemplo n.º 4
0
static PyObject *Session_search(Session *self, PyObject *args, PyObject *kwds) {
    char *query;
    sp_search *search;
    PyObject *callback, *userdata;
    int track_offset=0, track_count=32,
        album_offset=0, album_count=32,
        artist_offset=0, artist_count=32;
    search_trampoline *st;
    static char *kwlist[] = {"query", "callback",
                             "track_offset", "track_count",
                             "album_offset", "album_count",
                             "artist_offset", "artist_count",
                             "userdata", NULL
                            };
    PyArg_ParseTupleAndKeywords(args, kwds, "sO|iiiiiiO", kwlist, &query, &callback,
                                &track_offset, &track_count, &album_offset, &album_count,
                                &artist_offset, &artist_count, &userdata);
    Py_INCREF(userdata);
    Py_INCREF(callback);
    st = malloc(sizeof(search_trampoline));
    st->userdata = userdata;
    st->callback = callback;
    Py_BEGIN_ALLOW_THREADS
    search = sp_search_create(self->_session, query,
                              track_offset, track_count,
                              album_offset, album_count,
                              artist_offset, artist_count,
                              search_complete, (void *)st);
    Py_END_ALLOW_THREADS
    Results *results = (Results *)PyObject_CallObject((PyObject *)&ResultsType, NULL);
    Py_INCREF(results);
    results->_search = search;
    return (PyObject *)results;
}
Exemplo n.º 5
0
void sess_search(const char *query)
{
  if (g_session.state != SESS_ONLINE) {
    log_append("Not connected");
    return;
  }

  log_append("Searching for: <%s>", query);
  sp_search *res = sp_search_create(g_session.spotify, query,
      0, 200, // tracks
      0,   0, // albums
      0,   0, // artists
      sess_cb_search_complete_cb, NULL);

  if (!res)
    panic("sp_search_create() failed");

  sess_search_t *prev = g_session.search;
  sess_search_t *search = malloc(sizeof(sess_search_t));
  search->res  = res;
  search->next = prev;
  g_session.search = search;
  ++g_session.search_len;

  sidebar_reset();
}
Exemplo n.º 6
0
void resolve(list<int> int_params, list<string> string_params, sp_session *session, sp_track *track) {
	if (session == NULL)
		exitl("Tried to resolve before session was initialized");
    string *qid = new string(string_params.front());
	string query = string_params.back();
	log("resolve| session is %s, query:'%s' qid:'%s'", session==0?"null":"not null", query.c_str(), qid->c_str());
    sp_search_create(session, query.c_str(), 0, 100, 0, 100, 0, 100, 0, 100, SP_SEARCH_STANDARD, &search_complete, qid);
    log("Beginning to resolve query:'%s', qid:'%s'", query.c_str(), qid->c_str());
}
void SpotifyClient::Search(const spotify_pb::SearchRequest& req) {
  sp_search* search = sp_search_create(
        session_, req.query().c_str(),
        0, req.limit(),
        0, req.limit_album(),
        0, 0, // artists
        &SearchCompleteCallback, this);

  pending_searches_[search] = req;
}
Exemplo n.º 8
0
static void send_reply(struct mg_connection *conn) {
  if(!strcmp(conn->uri, "/search")) {
        printf("Received \"search\" request.\n");
        fflush(stdout);

		//mg_printf_data(conn, "Search %s", conn->query_string);
		//Call search function
		
        int isLoaded = 0;
        sp_search* search = sp_search_create(g_sess, conn->query_string, 0, 100, 0, 100, 0, 100, 0, 100, SP_SEARCH_STANDARD, &search_complete, &isLoaded);
		int timeout = 0;
		sp_session_process_events(g_sess, &timeout);
		while(!isLoaded) {
			usleep(100000);
			printf("Waiting...\n");
			sp_session_process_events(g_sess, &timeout);
		}
//    pthread_mutex_lock(&g_search_mutex);

//    while (!isLoaded) {
//    while(!sp_search_is_loaded(search)) {
//        printf("Waiting...\n");
//        fflush(stdout);
//        pthread_cond_wait(&g_search_cond, &g_search_mutex);
//        printConnectionState();
//        print_search_error(search);
//        usleep(1000000);
//    }
//    printf("Received search_complete signal.");
//    fflush(stdout);
    char* rv = search_to_json(search);
//    pthread_mutex_unlock(&g_search_mutex);

        sp_search_release(search);

        mg_printf_data(conn, rv);

	} else if(!strcmp(conn->uri, "/upvote")) {
		mg_printf_data(conn, "Upvote %s", conn->query_string);
		//call upvote function
		mg_printf_data(conn,"Upvoted");
		upvoteHelper(conn->query_string);
		try_playback_start();
	} else if(!strcmp(conn->uri, "/queue")) {
		//call queue function
		// TODO: print this to user not console printf(print_queue());
		mg_printf_data(conn,print_queue());
	} else if(!strcmp(conn->uri, "/key")) {
		//mg_printf_data(conn, "Key: %d", g_appkey[0]);
		// this is not part of our project. it will not be done.
	} else if(!strcmp(conn->uri, "/ping")) {
		mg_printf_data(conn,"Hello. Partyfy is running.");
 	} else {
	}
}
Exemplo n.º 9
0
Spotify::Error Spotify::Session::search( const QString& query, const int trackOffset, const int trackCount,
                                         const int albumOffset, const int albumCount, const int artistOffset,
                                         const int artistCount, void* userdata )
{
    Spotify::Error error;
    sp_search* search = sp_search_create( m_session, query.toUtf8().data(), trackOffset, trackCount,
                                          albumOffset, albumCount, artistOffset, artistCount,
                                          &searchCompleteCallback, userdata );

    Spotify::Search* s = new Spotify::Search( search );
    m_searchHash.insert( search, s );
    connect( s, SIGNAL(destroyed(QObject*)),
             this, SLOT(searchDeletedSlot(QObject*)));
    return error;
}
Exemplo n.º 10
0
void QSpotifySearch::searchTracks()
{
    setBusy(true);

    if (!m_query.isEmpty()) {
        QMutexLocker lock(&g_mutex);
        auto typePtr = new SearchTypePass(Tracks);
        m_sp_search = sp_search_create(
                    QSpotifySession::instance()->m_sp_session,
                    m_query.toUtf8().constData(),
                    0, m_tracksLimit, 0, 0,
                    0, 0, 0, 0,
                    sp_search_type(m_searchType), callback_search_complete, typePtr);
        g_searchObjects.insert(m_sp_search, this);
    }
}
Exemplo n.º 11
0
  Search::Search(string query) {
    m_maxArtistResults = Settings::getInstance()->getSearchNumberArtists();
    m_maxAlbumResults = Settings::getInstance()->getSearchNumberAlbums();
    m_maxTrackResults = Settings::getInstance()->getSearchNumberTracks();

    m_query = query;

    m_artistsDone = false;
    m_albumsDone = false;
    m_tracksDone = false;

    //do the initial search
    m_cancelSearch = false;
    Logger::printOut("creating search");
    Logger::printOut(query);
    m_currentSearch = sp_search_create(Session::getInstance()->getSpSession(), m_query.c_str(), 0, m_maxTrackResults, 0, m_maxAlbumResults, 0, m_maxArtistResults, &cb_searchComplete, this);

  }
Exemplo n.º 12
0
int cmd_search(int argc, char **argv)
{
  char query[1024];
  int i;

  if (argc < 2) {
    search_usage();
    return -1;
  }

  query[0] = 0;
  for(i = 1; i < argc; i++)
    snprintf(query + strlen(query), sizeof(query) - strlen(query), "%s%s",
       i == 1 ? "" : " ", argv[i]);

  sp_search_create(g_session, query, 0, 100, 0, 100, 0, 100, &search_complete, NULL);
  return 0;
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: delrtye/Spot
void run_search(sp_session *session)
{
	// ask the user for an artist and track
	char artist[1024];
	printf("Artist: ");
	fgets(artist, 1024, stdin);
	artist[strlen(artist)-1] = '\0';

	char track[1024];
	printf(" Track: ");
	fgets(track, 1024, stdin);
	track[strlen(track)-1] = '\0';

	char q[4096];
	sprintf(q, "artist:\"%s\" track:\"%s\"", artist, track);

	// start the search
	sp_search_create(session, q, 0, 1, 0, 0, 0, 0, 0, 0, SP_SEARCH_STANDARD, &on_search_complete, session);
}
Exemplo n.º 14
0
static PyObject *
Session_search(PyObject *self, PyObject *args, PyObject *kwds)
{
    PyObject *callback, *userdata = NULL;
    Callback *trampoline;

    char *query;
    sp_search *search;
    sp_search_type search_type = SP_SEARCH_STANDARD;

    int track_offset = 0, track_count = 32, album_offset = 0, album_count = 32,
        artist_offset = 0, artist_count = 32, playlist_offset = 0,
        playlist_count = 32;

    static char *kwlist[] = {
        "query", "callback", "track_offset", "track_count", "album_offset",
        "album_count", "artist_offset", "artist_count", "playlist_offset",
        "playlist_count", "search_type", "userdata", NULL };

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "esO|iiiiiiiiO&O", kwlist,
                                     ENCODING, &query, &callback,
                                     &track_offset, &track_count,
                                     &album_offset, &album_count,
                                     &artist_offset, &artist_count,
                                     &playlist_offset, &playlist_count,
                                     &sp_search_type_converter,
                                     (void *)&search_type, &userdata))
        return NULL;

    trampoline = create_trampoline(callback, userdata);

    Py_BEGIN_ALLOW_THREADS;
    search = sp_search_create(Session_SP_SESSION(self), query, track_offset,
                              track_count, album_offset, album_count,
                              artist_offset, artist_count, playlist_offset,
                              playlist_count, search_type,
                              Session_search_complete, (void *)trampoline);
    Py_END_ALLOW_THREADS;
    PyMem_Free(query);

    return Results_FromSpotify(search, 0 /* add_ref */);
}
Exemplo n.º 15
0
int cmd_search(int argc, char **argv)
{
        char query[1024];
        int i;

        if (argc < 2) {
                search_usage();
                return -1;
        }

        query[0] = 0;
        for(i = 1; i < argc; i++)
                snprintf(query + strlen(query), sizeof(query) - strlen(query), "%s%s",
                         i == 1 ? "" : " ", argv[i]);
#ifdef USE_MYSQL
                _mysql_updateStats(g_conn, "search");
#endif
        sp_search_create(g_session, query, 0, 100, 0, 100, 0, 100, &search_complete, NULL);
        return 0;
}
Exemplo n.º 16
0
void run_search(sp_session *session)
{
	// ask the user for an artist and track
	printf("\n--Search and play--\n");
	char artist[1024];
	printf("Artist: ");
	fgets(artist, 1024, stdin);
	artist[strlen(artist)-1] = '\0';

	char track[1024];
	printf("Track: ");
	fgets(track, 1024, stdin);
	track[strlen(track)-1] = '\0';

	// format the query, e.g. "artist:<artist> track:<track>"
	char q[4096];
	sprintf(q, "artist:\"%s\" track:\"%s\"", artist, track);

	// start the search
	sp_search_create(session, q, 0, 1, 0, 0, 0, 0, 0, 0, SP_SEARCH_STANDARD,
			&search_complete, session);
}
Exemplo n.º 17
0
static PyObject *
Session_search(Session * self, PyObject *args, PyObject *kwds)
{
    char *query;
    sp_search *search;
    PyObject *callback, *userdata = NULL;
    int track_offset = 0, track_count = 32,
        album_offset = 0, album_count = 32, artist_offset = 0, artist_count =
        32;
    Callback *st;
    PyObject *results;

    static char *kwlist[] = { "query", "callback",
        "track_offset", "track_count",
        "album_offset", "album_count",
        "artist_offset", "artist_count",
        "userdata", NULL
    };
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "esO|iiiiiiO", kwlist,
                                     ENCODING, &query, &callback,
                                     &track_offset, &track_count,
                                     &album_offset, &album_count,
                                     &artist_offset, &artist_count, &userdata))
        return NULL;
    if (!userdata)
        userdata = Py_None;
    st = create_trampoline(callback, NULL, userdata);
    Py_BEGIN_ALLOW_THREADS;
    search = sp_search_create(self->_session, query,
                              track_offset, track_count,
                              album_offset, album_count,
                              artist_offset, artist_count,
                              (search_complete_cb *) search_complete,
                              (void *)st);
    Py_END_ALLOW_THREADS;
    results = Results_FromSpotify(search);
    return results;
}
Exemplo n.º 18
0
void command_search(sp_session *session, const struct command * const command)
{
	if(command->search_string == NULL)
	{
		LOG_PRINT("execute_command: search_string is null-ptr.\n");
	}
	else
	{
		sp_search_create(session, 
			command->search_string,
			0,
			NUM_SEARCH_RESULTS,
			0,
			NUM_SEARCH_RESULTS,
			0,
			NUM_SEARCH_RESULTS,
			0,
			0,
			SP_SEARCH_STANDARD,
			&on_search_complete,
			session
		);
	}
}
Exemplo n.º 19
0
void
SpotifySearch::searchComplete( sp_search *result, void *userdata )
{
    UserData* data = reinterpret_cast<UserData*>( userdata );
    qDebug() << "Got search result for qid:" << data->qid;

    // we return the top 50 results for searches, just top 1 for resolve
    QVariantMap resp;
    resp[ "qid" ] = data->qid;
    resp[ "_msgtype" ] = "results";
    QVariantList results;

    // TODO search by popularity!
    qDebug() << "Got num results:" << sp_search_num_tracks( result );
    if( sp_search_num_tracks( result ) > 0 ) {// we have a result
        int num = qMin( sp_search_num_tracks( result ), data->fulltext ? 50 : 1 );
        for( int i = 0; i < num; i++ ) {
            sp_track *const tr = sp_search_track( result, i );
            if( !tr || !sp_track_is_loaded( tr ) ) {
                qDebug() << "Got still loading track, skipping";
                continue;
            }

            sp_link* link  = sp_link_create_from_track( tr, 0 );
            QString uid = data->resolver->addToTrackLinkMap( link );

            int duration = sp_track_duration( tr ) / 1000;
            QVariantMap track;
            track[ "track" ] = QString::fromUtf8( sp_track_name( tr ) );
            track[ "artist" ] = QString::fromUtf8( sp_artist_name( sp_track_artist( tr, 0 ) ) );
            track[ "album" ] = QString::fromUtf8( sp_album_name( sp_track_album( tr ) ) );
            track[ "albumpos" ] = sp_track_index( tr );
            track[ "discnumber"] = sp_track_disc( tr );
            track[ "year" ] = sp_album_year( sp_track_album( tr ) );
            track[ "mimetype" ] = "audio/basic";
            track[ "source" ] = "Spotify";
            track[ "url" ] = QString( "http://localhost:%1/sid/%2.wav" ).arg( data->resolver->port() ).arg( uid );
            track[ "duration" ] = duration;
            track[ "score" ] = .95; // TODO
            track[ "bitrate" ] = 192; // TODO

            // 8 is "magic" number. we don't know how much spotify compresses or in which format (mp3 or ogg) from their server, but 1/8th is approximately how ogg -q6 behaves, so use that for better displaying
            quint32 bytes = ( duration * 44100 * 2 * 2 ) / 8;
            track[ "size" ] = bytes;
            results << track;
            data->searchCount = 0;
            //qDebug() << "Found Track:" << sp_track_name( tr ) << "\n\tReporting:" << track["url"];
        }

    }else
    {
        QString didYouMean = QString::fromUtf8(sp_search_did_you_mean(	result ) );
        if(data->searchCount <= 1  ){
            qDebug() << "Try nr." << data->searchCount << " Searched for" << QString::fromUtf8(sp_search_query(	result ) ) << "Did you mean?"<< didYouMean;
            //int distance = QString::compare(QString::fromUtf8(sp_search_query(	result ) ), QString::fromUtf8(sp_search_did_you_mean(	result ) ), Qt::CaseInsensitive);
            //qDebug() << "Distance for query is " << distance;//if( distance < 4)
            sp_search_create( SpotifySession::getInstance()->Session(), sp_search_did_you_mean(	result ) , 0, data->fulltext ? 50 : 1, 0, 0, 0, 0, &SpotifySearch::searchComplete, data );
            data->searchCount++;
            return;
        }

    }

    resp[ "results" ] = results;
    sp_search_release( result );
    data->resolver->sendMessage( resp );
}
Exemplo n.º 20
0
sp_search* search_create(const gchar* query, search_complete_cb* callback, gpointer userdata) {
    int nb_results = config_get_int_opt("search_results", 100);
    return sp_search_create(g_session, query,
                            0, nb_results, 0, nb_results, 0, nb_results, 0, nb_results,
                            SP_SEARCH_STANDARD, callback, userdata);
}
Exemplo n.º 21
0
int cmd_whatsnew(int argc, char **argv)
{
  sp_search_create(g_session, "tag:new", 0, 0, 0, 250, 0, 0, &search_complete, NULL);
  return 0;
}
Exemplo n.º 22
0
int session_search(char *pattern)
{
	sp_search_create(g_session, pattern, 0, 20, 0, 20, 0, 20, 0, 20, SP_SEARCH_STANDARD, &search_complete, NULL);
	return 0;
}