mpdlen.c (669B)
1 #include <stdio.h> 2 3 #include <mpd/client.h> 4 5 /* usage: mpdlen [list] */ 6 7 int 8 main(int argc, char *argv[]) 9 { 10 struct mpd_connection *conn; 11 struct mpd_song *song; 12 unsigned secs = 0; 13 char *list = argv[1]; 14 15 conn = mpd_connection_new(NULL, 0, 0); 16 17 if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) 18 err(1, "mpd_connection_new"); 19 20 if (list != NULL) 21 mpd_send_list_playlist_meta(conn, list); 22 else 23 mpd_send_list_queue_meta(conn); 24 25 while ((song = mpd_recv_song(conn)) != NULL) { 26 secs += mpd_song_get_duration(song); 27 mpd_song_free(song); 28 } 29 30 mpd_connection_free(conn); 31 32 printf("%02u:%02u:%02u\n", secs / 3600, secs % 3600 / 60, secs % 60); 33 34 return 0; 35 }