Ejemplo n.º 1
0
QSpotifySession::~QSpotifySession()
{
    qDebug() << "QSpotifySession::cleanUp";
    if (m_sp_session)
        sp_session_release(m_sp_session);
    free(dataPath);
}
SpotifyClient::~SpotifyClient() {
  if (session_) {
    sp_session_release(session_);
  }

  free(const_cast<char*>(spotify_config_.cache_location));
  free(const_cast<char*>(spotify_config_.settings_location));
  free(const_cast<void*>(spotify_config_.application_key));
}
QSpotifySession::~QSpotifySession()
{
    qDebug() << "QSpotifySession::cleanUp";
    if (m_sp_session)
        sp_session_release(m_sp_session);
    free(dataPath);
    m_cleaned = true;
    qDebug() << "QSpotifySession::cleanUp finished";
}
Ejemplo n.º 4
0
Spotify::~Spotify()
{
    if (sp) {
        sp_session_release(sp);
        sp = 0;
    }
    audioThread.quit();
    audioThread.wait();
}
Ejemplo n.º 5
0
	void Session::Shutdown()
	{
		if (m_pSession)
		{			
						
			// clear any remaining events
			Update();
			// release the session
			sp_session_release( m_pSession );
			
			m_pSession = NULL;
		}		
	}
Ejemplo n.º 6
0
int session_release(void)
{
	sp_error error;

	error = sp_session_release(g_session);
	if (error != SP_ERROR_OK) {
		fprintf(stderr, "failed to release session: %s\n",
				sp_error_message(error));
		return -1;
	}

	return 0;
}
Ejemplo n.º 7
0
static void logged_in(sp_session *session, sp_error error)
{
	spotify_object *p = sp_session_userdata(session);
	p->is_logged_in = 1;

	if (SP_ERROR_OK != error) {
		p->is_logged_out = 1;
		sp_session_release(session);

		char *errMsg;
		spprintf(&errMsg, 0, "login failed: %s", sp_error_message(error));
		zend_throw_exception((zend_class_entry*)zend_exception_get_default(), errMsg, 0 TSRMLS_CC);
	}
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
  bool Session::disConnect() {
  	if (m_isEnabled) {
      Logger::printOut("Logging out");

      PlayerHandler::deInit();
      Logger::printOut("cleaned player");

      //delete m_playlists;
      //m_playlists = NULL;
      Logger::printOut("cleaned playlists");

      //SearchHandler::deInit();
      Logger::printOut("cleaned search");

      //RadioHandler::deInit();
      Logger::printOut("cleaned radios");

      //ArtistStore::deInit();
      Logger::printOut("cleaned artists");

      //AlbumStore::deInit();
      Logger::printOut("cleaned albums");

      //TrackStore::deInit();
      Logger::printOut("cleaned tracks");

      ThumbStore::deInit();
      Logger::printOut("cleaned thumbs");

      //TODO FIX THE LOGOUT... Why is it crashing on logout?
      m_isLoggedOut = false;
      sp_session_logout(m_session);

      Logger::printOut("logged out waiting for callback");
      while (!m_isLoggedOut) {
        processEvents();
      }
      Logger::printOut("logged out");
      sp_session_release(m_session);
      Logger::printOut("cleaned session");
  	}
    return true;
  }
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
int __cdecl main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *blob = argc > 2 ? argv[2] : NULL;
	const char *password = NULL;
	int selftest = argc > 3 ? !strcmp(argv[3], "selftest") : 0;
	char username_buf[256];
	char password_buf[256];
	int r;
	int next_timeout = 0;
	DWORD ev;
	DWORD mode;

	events[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
	events[1] = GetStdHandle(STD_INPUT_HANDLE);

	printf("Using libspotify %s\n", sp_build_id());

	if (username == NULL) {
		printf("Username: (just press enter to login with stored credentials): ");
		fflush(stdout);
		fgets(username_buf, sizeof(username_buf), stdin);
		trim(username_buf);
		if(username_buf[0] == 0) {
			username = NULL;
		} else {
			username = username_buf;
		}
	}

	// If a username was supplied but no blob, prompt for password
	if (username != NULL && blob == NULL) {
		printf("Password: "******"Unable to set console mode err=%d\n", GetLastError());
			exit(1);
		}

		fgets(password_buf, sizeof(password_buf), stdin);
		trim(password_buf);
		password = password_buf;
		printf("\r\n");
	}

	if ((r = spshell_init(username, password, blob, selftest)) != 0)
		exit(r);

	if (!SetConsoleMode(events[1], ENABLE_PROCESSED_INPUT)) {
		printf("Unable to set console mode err=%d\n", GetLastError());
		exit(1);
	}

	while(!is_logged_out) {
		ev = WaitForMultipleObjects(1 + enable_console, events, FALSE, next_timeout > 0 ? next_timeout : INFINITE);
		switch (ev) {
		case WAIT_OBJECT_0 + 0:
		case WAIT_TIMEOUT:
			do {
				sp_session_process_events(g_session, &next_timeout);
			} while (next_timeout == 0);

			if(g_selftest)
				test_process();
			break;

		case WAIT_OBJECT_0 + 1:
			console_input();
			break;
		}
	}
	printf("Logged out\n");
	sp_session_release(g_session);
	printf("Exiting...\n");
	return 0;
}
Ejemplo n.º 12
0
int main(int argc, char** argv)
{
	for (;;) {
		int option_index = 0;
		int c = getopt_long(argc, argv, "hl:u:p:r", NULL, &option_index);
		if (c == -1) {
			break ;
		}
		switch (c) {
		case 'h':
			usage();
			break;
		case 'l':
			playlist_name = strdup(optarg);
			break;
		case 'u':
			user_name = strdup(optarg);
			break;
		case 'p':
			password = strdup(optarg);
			break;
		case 'r':
			reset = true;
			break;
			
		};
	}

	// setup our spotify config
	sp_session_config config;
	memset(&config, 0, sizeof(config));
	config.api_version = SPOTIFY_API_VERSION;
	
	
	config.cache_location = "/tmp/spiffify";
	config.settings_location = "/tmp/spiffify";
	config.application_key = g_appkey;
	config.application_key_size = g_appkey_size;

	/* mkdir(config.cache_location, 0); */
	/* mkdir(config.settings_location, 0); */

	
	config.user_agent = "spiffify";

	sp_session_callbacks callbacks;
	memset(&callbacks, 0, sizeof(callbacks));
	callbacks.logged_in = &logged_in;
	/* callbacks.logged_out = logged_out; */
	callbacks.connection_error = &connection_error; 
	callbacks.notify_main_thread = &notify_main_thread;

	config.callbacks = &callbacks;

	// setup waits
	pthread_mutex_init(&g_mutex, NULL);
	pthread_cond_init(&g_cond, NULL);


	sp_error error = sp_session_create(&config, &session);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not create session: %s\n", sp_error_message(error));
		abort();
	}

	error = sp_session_login(session, user_name, password, 0, NULL);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not initiate login: %s\n", sp_error_message(error));
		abort();
	}
	pthread_mutex_lock(&g_mutex);


	int next_timeout=0;
	int load_completed=0;
	int messaged_load_waiting=0;
	for(;;) {
		if (next_timeout == 0) {
            while(!g_notify_do) {
                pthread_cond_wait(&g_cond, &g_mutex);
			}
		}
		else {
            struct timespec ts;

#if _POSIX_TIMERS > 0
            clock_gettime(CLOCK_REALTIME, &ts);
#else
            struct timeval tv;
            gettimeofday(&tv, NULL);
            TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif

            pthread_cond_timedwait(&g_cond, &g_mutex, &ts);
        }

        g_notify_do = 0;
        pthread_mutex_unlock(&g_mutex);

        do {
            sp_session_process_events(session, &next_timeout);
			if (load_completed == 0 && validate_complete_load()) {
				if (did_spiffify == 0 ) {
					spiffify();
					did_spiffify = 1;
				}
				sp_session_process_events(session, &next_timeout);
				// when the container_loaded event comes back (don't ask) we can be sure that our stuff made it to the server and we can exit there.
				if (can_exit==1) {
					goto done;
				}
			}
			else {
				if (messaged_load_waiting==0) {
					printf("Load not completed.. waiting\n");
					messaged_load_waiting = 1;
				}
			}
        } while (next_timeout == 0);

        pthread_mutex_lock(&g_mutex);
	}

done:
	error = sp_session_logout(session);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not logout: %s\n", sp_error_message(error));
		exit(1);
	}
	error = sp_session_release(session);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not destroy session: %s\n", sp_error_message(error));
		exit(1);
	}
};
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *password = argc > 2 ? argv[2] : NULL;
	int selftest = argc > 3 ? !strcmp(argv[3], "selftest") : 0;
	char username_buf[256];
	int r;
	int next_timeout = 0;

	printf("Using libspotify %s\n", sp_build_id());

	if (username == NULL) {
		printf("Username (just press enter to login with stored credentials): ");
		fflush(stdout);
		fgets(username_buf, sizeof(username_buf), stdin);
		trim(username_buf);
		if(username_buf[0] == 0) {
			username = NULL;
		} else {
			username = username_buf;
		}
	}

	if (username != NULL && password == NULL)
		password = getpass("Password: "******"Logged out\n");
	sp_session_release(g_session);
	printf("Exiting...\n");
	return 0;
}
Ejemplo n.º 14
0
void destroy(list<int> int_params, list<string> string_params, sp_session *session, sp_track *track) {
	sp_session_release(session);
	destroy_audio_player();
}