Statistics Connection::getStatistics() { prechecks(); mpd_stats *stats = mpd_run_stats(m_connection.get()); checkErrors(); return Statistics(stats); }
/* * Retrieves status about the state of MPD. */ bool Control::get_status() { mpd_status * status; mpd_stats * stats; EXIT_IDLE; pms->log(MSG_DEBUG, 0, "Retrieving MPD status from server.\n"); if ((status = mpd_run_status(conn->h())) == NULL) { /* FIXME: error handling? */ pms->log(MSG_DEBUG, 0, "mpd_run_status returned NULL pointer.\n"); delete _song; _song = NULL; st->song = MPD_SONG_NO_NUM; st->songid = MPD_SONG_NO_ID; return false; } st->assign_status(status); mpd_status_free(status); if ((stats = mpd_run_stats(conn->h())) == NULL) { /* FIXME ? */ pms->log(MSG_DEBUG, 0, "mpd_run_stats returned NULL pointer.\n"); return false; } st->assign_stats(stats); mpd_stats_free(stats); return true; }
void get_random_song(struct mpd_connection *conn, char *str, char *path) { struct mpd_entity *entity; int listened0 = 65000, skipnum, numberofsongs = 0; struct mpd_stats *stats = mpd_run_stats(conn); if (stats == NULL) return; numberofsongs = mpd_stats_get_number_of_songs(stats); mpd_stats_free(stats); skipnum = rand() % numberofsongs; syslog(LOG_DEBUG, "%s: path %s; number of songs: %i skip: %i\n", __func__, path, numberofsongs, skipnum); if (!mpd_send_list_all_meta(conn, ""))//path)) { syslog(LOG_ERR, "%s: error: mpd_send_list_meta %s\n", __func__, path); return; } while((entity = mpd_recv_entity(conn)) != NULL) { const struct mpd_song *song; if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) { if (skipnum-- > 0) continue; int listened; song = mpd_entity_get_song(entity); listened = db_get_song_numplayed(mpd_get_title(song), mpd_get_artist(song)); if (listened < listened0) { listened0 = listened; syslog(LOG_DEBUG, "listened: %i ", listened); int probability = 50 + db_get_song_rating(mpd_get_title(song), mpd_get_artist(song)); syslog(LOG_DEBUG, "probability: %i ", probability); bool Yes = (rand() % 100) < probability; if (Yes) { sprintf(str, "%s", mpd_song_get_uri(song)); syslog(LOG_DEBUG, "uri: %s ", str); syslog(LOG_DEBUG, "title: %s ", mpd_get_title(song)); syslog(LOG_DEBUG, "artist: %s", mpd_get_artist(song)); } } } mpd_entity_free(entity); } }
int update_client(CLIENT_OBJECT *cli) { mpd_status_free(cli->status); cli->status = mpd_run_status(cli->conn); if (cli->song) mpd_song_free(cli->song); cli->song = mpd_run_current_song(cli->conn); mpd_stats_free(cli->stats); cli->stats = mpd_run_stats(cli->conn); return 0; }
CLIENT_OBJECT * new_client() { CLIENT_OBJECT *cli = (CLIENT_OBJECT *)malloc(sizeof(*cli)); cli->conn = mpd_connection_new(NULL,0,0); cli->status = mpd_run_status(cli->conn); cli->song = mpd_run_current_song(cli->conn); cli->stats = mpd_run_stats(cli->conn); if (!(cli->conn && cli->status && cli->stats)) return NULL; cli->idle = false; return cli; }
int cmd_stats(gcc_unused int argc, gcc_unused char **argv, struct mpd_connection *conn) { struct mpd_stats *stats = mpd_run_stats(conn); if (stats == NULL) printErrorAndExit(conn); printf("Artists: %6d\n", mpd_stats_get_number_of_artists(stats)); printf("Albums: %6d\n", mpd_stats_get_number_of_albums(stats)); printf("Songs: %6d\n", mpd_stats_get_number_of_songs(stats)); printf("\n"); printf("Play Time: %s\n", DHMS(mpd_stats_get_play_time(stats))); printf("Uptime: %s\n", DHMS(mpd_stats_get_uptime(stats))); time_t t = mpd_stats_get_db_update_time(stats); printf("DB Updated: %s", ctime(&t)); /* no \n needed */ printf("DB Play Time: %s\n", DHMS(mpd_stats_get_db_play_time(stats))); mpd_stats_free(stats); return 0; }
/* * Returns: 0 - error; 1 - ok */ int mgr_mpd_fetch_status( struct mpd_connection *conn, int dump_status ) { struct mpd_status *status; struct mpd_stats *stats; if (DEBUG > 1) fprintf(stderr, "DEBUG: [mgr-thread] mpd: -status fetching...\n"); if (conn == NULL) { fprintf(stderr, "ERROR: MPD: Unable to retrieve the MPD status: not connected\n"); return 0; } if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { fprintf(stderr, "ERROR: MPD: Unable to retrieve MPD status: connection error\n"); return 0; } if (DEBUG > 1) fprintf(stderr, "DEBUG: [mgr-thread] mpd: run status\n"); status = mpd_run_status(conn); if (!status) { fprintf(stderr, "ERROR: MPD: Unable to retrieve MPD status\n"); return 0; } cur_mpd_player_status = mpd_status_get_state(status); if (DEBUG > 1) { fprintf(stderr, "DEBUG: [mgr-thread] mpd: +status received:\n"); } if (DEBUG && dump_status) { fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => mode : %s\n", (cur_mpd_player_status == MPD_STATE_PLAY ? "Play" : "Other")); fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => random : %d\n", mpd_status_get_random(status)); fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => repeat : %d\n", mpd_status_get_random(status)); fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => volume : %d\n", mpd_status_get_volume(status)); fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => queue ver : %d\n", mpd_status_get_queue_version(status)); fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => queue len : %d\n", mpd_status_get_queue_length(status)); } cur_mpd_random = mpd_status_get_random(status) ? 1 : 0; cur_mpd_volume = mpd_status_get_volume(status); cur_mpd_status_queue_len = mpd_status_get_queue_length(status); if (DEBUG > 1) fprintf(stderr, "DEBUG: [mgr-thread] mpd: release status\n"); if (mpd_status_get_error(status) != NULL) { fprintf(stderr, "WARNING: MPD: Error Received from MPD: %s\n", mpd_status_get_error(status)); // TODO - clear error } mpd_status_free(status); mpd_response_finish(conn); stats = mpd_run_stats(conn); if (stats == NULL) { fprintf(stderr, "ERROR: MPD: Unable to retrieve MPD statistics\n"); return 0; } cur_mpd_stats_number_of_songs = mpd_stats_get_number_of_songs( stats ); if (DEBUG && dump_status) { fprintf(stderr, "DEBUG: [mgr-thread] mpd stats : => # of songs: %d\n", cur_mpd_stats_number_of_songs); } mpd_stats_free( stats ); return 1; }
void CMPD::Update() { if(!_connected) { iprintf("Reconnecting in 10 seconds."); sleep(10); if(Connect()) iprintf("%s", "Reconnected!"); else { eprintf("%s", "Could not reconnect."); return; } } mpd_status *status = mpd_run_status(_conn); mpd_stats *stats = mpd_run_stats(_conn); if(status && stats) { int newsongid = mpd_status_get_song_id(status); int newsongpos = mpd_status_get_elapsed_time(status); int curplaytime = mpd_stats_get_play_time(stats); // new song if(newsongid != _songid) { _songid = newsongid; _songpos = newsongpos; _start = curplaytime; mpd_song *song = mpd_run_current_song(_conn); if(song) { GotNewSong(song); mpd_song_free(song); } } // song playing if(newsongpos != _songpos) { _songpos = newsongpos; CheckSubmit(curplaytime); } // check for client-to-client messages if(mpd_send_read_messages(_conn)) { mpd_message *msg; while((msg = mpd_recv_message(_conn)) != NULL) { const char *text = mpd_message_get_text(msg); if(_gotsong && text && !strncmp(text, "love", 4)) AudioScrobbler->LoveTrack(_song); mpd_message_free(msg); } mpd_response_finish(_conn); } mpd_status_free(status); mpd_stats_free(stats); } else { // we have most likely lost our connection eprintf("Could not query MPD server: %s", mpd_connection_get_error_message(_conn)); _connected = false; } }