Пример #1
0
int main(int argc, char** argv)
{
	setlocale(LC_ALL, "");

	if (argc < 4)
	    {
		    printf("Usage: %s <username> <password> <out directory>\n", argv[0]);
		    return 1;
	    }

	if (!despotify_init())
	    {
		    wrapper_printf("despotify_init() failed");
		    return 1;
	    }

	struct despotify_session* ds = despotify_init_client(callback, NULL, true, true);
	if (!ds)
	    {
		    wrapper_printf("despotify_init_client() failed");
		    return 1;
	    }

	/* listen ? */
	if (!despotify_authenticate(ds, argv[1], argv[2]))
	    {
		    printf("Authentication failed: %s\n", despotify_get_error(ds));
		    despotify_exit(ds);
		    return 1;
	    }

	(void)print_playlists(ds, argv[3]);

	clean_and_exit(ds, EXIT_SUCCESS);

	return 0;
}
Пример #2
0
/**
* Handler to check user input, and see if it matches any avaible commands.
* Will call the right methods for executing commands
*/
void handle_keyboard(sp_session *session, struct play_queue* node)
{
    char buffer[1024];

    fgets(buffer, sizeof(buffer), stdin);
    strtok(buffer, "\n");

    if (strcmp(buffer, "search") == 0) {
        player_reset();
        run_search(session);

    } else if ((strcmp(buffer, "list") == 0) || (strcmp(buffer, "ls") == 0 )) {
        print_playlists(session, pc);

    } else if(strcmp(buffer, "qshuffle") == 0) {
        queue_shuffle();

    } else if (strcmp(buffer, "queueadd") == 0) {
        sp_playlist* pl = parse_play_command(session, buffer, node);
        printf("done finding playlist \n");

        if(pl != NULL) printf("queueadd: %s\n", sp_playlist_name(pl));
        else {
            printf("no playlist\n");
            return;
        }

        int index;
        char input[10];
        fputs("Song number: ", stdout);
        fgets(input, sizeof(input) - 1, stdin);
        sscanf(input, "%d", &index);
        if(sp_playlist_num_tracks(pl) < index) {
            printf("index too high!\n");
            return;
        }

        sp_track* track = pl_find_song_by_id(pl, index);
        if(track != NULL) queue_add_first(track);

    } else if (strcmp(buffer, "list songs") == 0 ) {
        //release all threads
        sp_playlist* pl = playlist_find_by_num(session, pc);
        print_tracks_in_playlist(session, pl);

    } else if (strcmp(buffer, "help") == 0) {
        print_commands();

    } else if (strcmp(buffer, "queue") == 0) {
        queue_print(node);

    } else if (strcmp(buffer, "shuffle mode") == 0) {
        print_commands();

    } else if(strncmp(buffer, "play", strlen("play")) == 0) {
        player_reset();
        sp_playlist* pl = parse_play_command(session, buffer, node);
        if(pl!=NULL) queue_add_playlist(pl);
        else {
            printf("ERROR playlist is null\n");
            return;
        }
        queue_go_next(session);


    } else if(strncmp(buffer, "shuffle", strlen("shuffle")) == 0) {
        player_reset();
        shuffle_mode = TRUE;
        sp_playlist* pl = parse_play_command(session, buffer, node);
        if(pl!=NULL) queue_add_playlist(pl);
        else {
            printf("ERROR playlist is null\n");
            return;
        }
        queue_shuffle();
        queue_go_next(session);

    } else if(strcmp(buffer, "pause") == 0 || strcmp(buffer, "p") == 0) {
        player_pause(session);
        play_info();

    } else if (strcmp(buffer, "next") == 0 || strcmp(buffer, "n") == 0) {
        end_track(session);

    } else if (strcmp(buffer, "stop") == 0) {

    } else if (strcmp(buffer, "info") == 0) {
        play_info();
    } else if (strcmp(buffer, "quit") == 0) {
        queue_free();
        quit_program(session);
    } else {
        printf("Unkown command!\n");
    }
    printf("> ");
    fflush(stdout);

    return;
}