Пример #1
0
static PyObject *
Session_set_preferred_bitrate(PyObject *self, PyObject *args)
{
    int bitrate;

    if (!PyArg_ParseTuple(args, "i", &bitrate))
        return NULL;

    sp_session_preferred_bitrate(Session_SP_SESSION(self), bitrate);
    Py_RETURN_NONE;
}
Пример #2
0
  bool Session::connect() {
    if (!m_session) {
      sp_session_config config;
      Logger::printOut("Creating session");
	 
      config.api_version = SPOTIFY_API_VERSION;
      Logger::printOut("API version:");
      char* version = new char[20];
      Logger::printOut(itoa(SPOTIFY_API_VERSION, version, 10));
	  
	  //the api is not copying the string so create a new c string
	  CStdString location = Settings::getCachePath();
	  char * cstr;
      cstr = new char [location.size()+1];
      strcpy (cstr, location.c_str());
      config.cache_location = cstr;
      config.settings_location = cstr;
      config.tracefile = NULL;

      config.application_key = g_appkey;
      config.application_key_size = g_appkey_size;
      config.user_agent = "spotyXBMC2";
      config.device_id = "XBMC htpc";

      sp_session_callbacks cb = m_sessionCallbacks.getCallbacks();
      config.callbacks = &cb;
      config.compress_playlists = true;
      config.dont_save_metadata_for_playlists = false;
      config.initially_unload_playlists = false;

      sp_error error = sp_session_create(&config, &m_session);

      if (SP_ERROR_OK != error) {
        Logger::printOut("Failed to create session: error:");
        Logger::printOut(sp_error_message(error));
        m_session = NULL;
        return false;
      }

      //set high bitrate
      if (Settings::useHighBitrate()) sp_session_preferred_bitrate(m_session, SP_BITRATE_320k);

      sp_session_set_connection_type(m_session, SP_CONNECTION_TYPE_WIRED);
      sp_session_set_connection_rules(m_session, SP_CONNECTION_RULE_NETWORK);
      sp_session_set_volume_normalization(m_session, Settings::useNormalization());

      sp_session_login(m_session, Settings::getUserName().c_str(), Settings::getPassword().c_str(), true);
      m_isEnabled = true;
      Logger::printOut("Logged in, returning");
      return true;
    }
    return false;
  }
Пример #3
0
void QSpotifySession::setStreamingQuality(StreamingQuality q)
{
    qDebug() << "QSpotifySession::setStreamingQuality";
    if (m_streamingQuality == q)
        return;

    m_streamingQuality = q;
    settings.setValue("streamingQuality", int(q));
    sp_session_preferred_bitrate(m_sp_session, sp_bitrate(q));

    emit streamingQualityChanged();
}
Пример #4
0
static PyObject *
Session_set_preferred_bitrate(Session * self, PyObject *args)
{
    int bitrate;

    if (!PyArg_ParseTuple(args, "i", &bitrate))
        return NULL;
    Py_BEGIN_ALLOW_THREADS;
    sp_session_preferred_bitrate(self->_session, bitrate);
    Py_END_ALLOW_THREADS;
    Py_RETURN_NONE;
}
Пример #5
0
sp_error session_init(sp_session **session)
{
	sp_error error;

	spconfig.application_key = &_binary_src_appkey_key_start;
	spconfig.application_key_size = (size_t)(&_binary_src_appkey_key_end - &_binary_src_appkey_key_start);

	if((error = sp_session_create(&spconfig, session)) != SP_ERROR_OK)
	{
		return error;
	}

	char *username = get_username();
	char *password = get_password();
	char *bitrate = get_bitrate();
	sp_bitrate preferred_bitrate;

	if (bitrate != NULL) {
		if (strcmp(bitrate, "160") == 0)
		{
			preferred_bitrate = SP_BITRATE_160k;
		} else if (strcmp(bitrate, "320") == 0)
		{
			preferred_bitrate = SP_BITRATE_320k;
		} else if (strcmp(bitrate, "96") == 0)
		{
			preferred_bitrate = SP_BITRATE_96k;
		} else
		{
			preferred_bitrate = SP_BITRATE_160k;
		}
	} else {
		preferred_bitrate = SP_BITRATE_160k;
	}

	sp_session_preferred_bitrate(*session, preferred_bitrate);

	error = sp_session_login(*session, username, password, 0, NULL);

	/*
	 * Don't keep a copy of the password in memory.
	 */
	memset(password, 0, strlen(password));
	free(password);
	free(username);

	return error;
}
Пример #6
0
static void
spotify_cb_logged_in (sp_session *spotify_session, sp_error error)
{
  if (SP_ERROR_OK != error) {
    GST_CAT_ERROR_OBJECT (gst_spot_src_debug_cb, ugly_spot, "Failed to log in to Spotify: %s", sp_error_message (error));
    return;
  }

  sp_user *me = sp_session_user (spotify_session);
  const char *my_name = (sp_user_is_loaded (me) ?
                         sp_user_display_name (me) :
                         sp_user_canonical_name (me));
  GST_CAT_DEBUG_OBJECT (gst_spot_src_debug_cb, ugly_spot, "Logged_in callback, user=%s", my_name);
  /* set default bitrate to audiofility */
  sp_session_preferred_bitrate(spotify_session, SP_BITRATE_320k);
  GST_SPOT_SRC_LOGGED_IN (ugly_spot) = TRUE;
}
Пример #7
0
void setbitrate(list<int> int_params, list<string> string_params, sp_session *session, sp_track *track) {
	if (session == NULL)
		exitl("Tried to setbitrate before session was initialized");
	int bitratemode = int_params.front();
	sp_bitrate bitrate;
	switch (bitratemode) {
        case 0:
            bitrate = SP_BITRATE_96k;
            break;
        case 1:
            bitrate = SP_BITRATE_160k;
            break;
        case 2:
            bitrate = SP_BITRATE_320k;
            break;
	}
	sp_error error = sp_session_preferred_bitrate(session, bitrate);
	log ("setbitrate set to mode " + bitratemode);
    if (error != SP_ERROR_OK)
        log ("!!!setbitrate error occurred: %s",sp_error_message(error));
}
Пример #8
0
/**********************
 *** Init functions ***
 **********************/
void session_init() {
    sp_error error;
    gchar* cache_path;

    g_debug("Creating session...");

    /* Cache path */
    cache_path = g_build_filename(g_get_user_cache_dir(), g_get_prgname(), NULL);

    /* libspotify session config */
    sp_session_config config = {
        .api_version = SPOTIFY_API_VERSION,
        .cache_location = cache_path,
        .settings_location = cache_path,
        .application_key = g_appkey,
        .application_key_size = g_appkey_size,
        .user_agent = "spop " SPOP_VERSION,
        .callbacks = &g_sp_session_callbacks,
        .userdata = NULL,
        .compress_playlists = FALSE,
        .dont_save_metadata_for_playlists = FALSE,
        .initially_unload_playlists = FALSE,
        NULL,
    };

    error = sp_session_create(&config, &g_session);
    if (error != SP_ERROR_OK)
        g_error("Failed to create session: %s", sp_error_message(error));

    /* Set bitrate */
    if (config_get_bool_opt("high_bitrate", TRUE)) {
        g_debug("Setting preferred bitrate to high.");
        sp_session_preferred_bitrate(g_session, SP_BITRATE_320k);
    }
    else {
        g_debug("Setting preferred bitrate to low.");
        sp_session_preferred_bitrate(g_session, SP_BITRATE_160k);
    }
    if (config_get_bool_opt("offline_high_bitrate", TRUE)) {
        g_debug("Setting preferred offline bitrate to high.");
        sp_session_preferred_offline_bitrate(g_session, SP_BITRATE_320k, FALSE);
    }
    else {
        g_debug("Setting preferred offline bitrate to low.");
        sp_session_preferred_offline_bitrate(g_session, SP_BITRATE_160k, FALSE);
    }

    size_t cache_size = config_get_int_opt("cache_size", 0);
    g_debug("Setting cache size to %zu.", cache_size);
    sp_session_set_cache_size(g_session, cache_size);

    g_debug("Session created.");
}

void session_login(const char* username, const char* password) {
    g_debug("Logging in...");
    if (!g_session)
        g_error("Session is not ready.");

    sp_session_login(g_session, username, password, TRUE, NULL);
}
Пример #9
0
	void Session::SetPreferredBitrate( sp_bitrate bitrate )
	{
		sp_session_preferred_bitrate( m_pSession, bitrate );
	}