void env_stats(struct mpd_stats *stats) { char *envstr; time_t t; char date[DEFAULT_DATE_FORMAT_SIZE] = { 0 }; t = mpd_stats_get_db_update_time(stats); strftime(date, DEFAULT_DATE_FORMAT_SIZE, DEFAULT_DATE_FORMAT, localtime(&t)); g_setenv("MPD_DATABASE_UPDATE_TIME", date, 1); envstr = g_strdup_printf("%d", mpd_stats_get_number_of_artists(stats)); g_setenv("MPD_DATABASE_ARTISTS", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_stats_get_number_of_albums(stats)); g_setenv("MPD_DATABASE_ALBUMS", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%d", mpd_stats_get_number_of_songs(stats)); g_setenv("MPD_DATABASE_SONGS", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%lu", mpd_stats_get_play_time(stats)); g_setenv("MPD_DATABASE_PLAY_TIME", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%lu", mpd_stats_get_uptime(stats)); g_setenv("MPD_DATABASE_UPTIME", envstr, 1); g_free(envstr); envstr = g_strdup_printf("%lu", mpd_stats_get_db_play_time(stats)); g_setenv("MPD_DATABASE_DB_PLAY_TIME", envstr, 1); g_free(envstr); }
static int lmpdstats_index(lua_State *L) { const char *key; struct mpd_stats **stats; stats = luaL_checkudata(L, 1, MPD_STATS_T); key = luaL_checkstring(L, 2); assert(*stats != NULL); if (strncmp(key, "number_of_artists", 18) == 0) { lua_pushinteger(L, mpd_stats_get_number_of_artists(*stats)); } else if (strncmp(key, "number_of_albums", 17) == 0) { lua_pushinteger(L, mpd_stats_get_number_of_albums(*stats)); } else if (strncmp(key, "number_of_songs", 16) == 0) { lua_pushinteger(L, mpd_stats_get_number_of_songs(*stats)); } else if (strncmp(key, "uptime", 7) == 0) { lua_pushinteger(L, mpd_stats_get_uptime(*stats)); } else if (strncmp(key, "db_update_time", 15) == 0) { lua_pushinteger(L, mpd_stats_get_uptime(*stats)); } else if (strncmp(key, "play_time", 10) == 0) { lua_pushinteger(L, mpd_stats_get_play_time(*stats)); } else if (strncmp(key, "db_play_time", 13) == 0) { lua_pushinteger(L, mpd_stats_get_db_play_time(*stats)); } else return luaL_error(L, "Invalid key `%s'", key); return 1; }
void mpd_query_stats(struct mpd_connection *conn) { struct mpd_stats *stats; if (!conn) return; if (!mpd_command_list_begin(conn, true) || !mpd_send_stats(conn) || !mpd_command_list_end(conn)) { mpd_printerror("queue_commands"); return; } stats = mpd_recv_stats(conn); if (stats == NULL) { mpd_printerror("recv_stats"); return; } l_numberOfSongs = mpd_stats_get_number_of_songs(stats); l_uptime = mpd_stats_get_uptime(stats); l_playTime = mpd_stats_get_play_time(stats); l_dbPlayTime = mpd_stats_get_db_play_time(stats); mpd_stats_free(stats); if (!mpd_response_finish(conn)) { mpd_printerror("response_finish"); return; } }
void Mpd_status::assign_stats(struct mpd_stats * stats) { artists_count = mpd_stats_get_number_of_artists(stats); albums_count = mpd_stats_get_number_of_albums(stats); songs_count = mpd_stats_get_number_of_songs(stats); uptime = mpd_stats_get_uptime(stats); db_update_time = mpd_stats_get_db_update_time(stats); playtime = mpd_stats_get_play_time(stats); db_playtime = mpd_stats_get_db_play_time(stats); }
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 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; }