Example #1
0
void scrobsub_pause()
{
    switch(state){
        case SCROBSUB_PAUSED:
             scrobsub_resume();
            break;
        case SCROBSUB_PLAYING:
            state = SCROBSUB_PAUSED;
            // we subtract pause_time so we continue to keep a record of the amount
            // of time paused so far
            pause_time = now() - pause_time;
            break;
    }
}
Example #2
0
static void submit()
{    
    //TODO check track is valid to submit
    
    if(state == SCROBSUB_PAUSED)
        scrobsub_resume(); //sets pause time correctly
    //FIXME the second resolution issue can introduce rounding errors
    if(now()-(start_time+pause_time) < scrobble_time(duration))
        return;
    
    int n = 32+N+4+2+10+1+1 +2+9*6;
#if SCROBSUB_NO_C99
    char* post_data = (char*)alloca(n); //alloca discouraged on BSD
#else
    char post_data[n];
#endif
    
    n = snprintf(post_data, n,
                     "s=%s"
                 "&a[0]=%s"
                 "&t[0]=%s"
                 "&b[0]=%s"
                 "&l[0]=%d"
                 "&n[0]=%d"
                 "&m[0]=%s"
                 "&i[0]=%d"
                 "&o[0]=%c"
                 "&r[0]=%c",
                 session_id, artist, track, album, duration, track_number, mbid, start_time, 'P', rating);
    
    for (int x=0; x<2; ++x){    
        char response[128];
        scrobsub_post(response, submit_url, post_data);
        
        if(ok(response)) break;
        printf("E: %s: %s%s", __FUNCTION__, response, post_data);
        if(strcmp(response, "BADSESSION\n") != 0) break;
        handshake();
    }
}