Only print playing song
This commit is contained in:
parent
53a2e60d87
commit
b0450da800
@ -196,7 +196,7 @@ void dbusStop( DBusConnection *conn, const char *player ) {
|
|||||||
dbus_message_unref( msg );
|
dbus_message_unref( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dbusStatus( DBusConnection *conn, const char *player ) {
|
char *dbusStatus( DBusConnection *conn, const char *player ) {
|
||||||
DBusMessageIter args;
|
DBusMessageIter args;
|
||||||
DBusMessageIter string;
|
DBusMessageIter string;
|
||||||
DBusMessage *msg = NULL;
|
DBusMessage *msg = NULL;
|
||||||
@ -208,9 +208,23 @@ bool dbusStatus( DBusConnection *conn, const char *player ) {
|
|||||||
char *meta = NULL;
|
char *meta = NULL;
|
||||||
dbus_message_iter_recurse( &args, &string );
|
dbus_message_iter_recurse( &args, &string );
|
||||||
dbus_message_iter_get_basic( &string, &meta );
|
dbus_message_iter_get_basic( &string, &meta );
|
||||||
bool ret = strcmp( meta, "Playing" ) == 0;
|
char *ret = strdup( meta );
|
||||||
ret |= strcmp( meta, "Paused" ) == 0;
|
|
||||||
// free reply
|
// free reply
|
||||||
dbus_message_unref( msg );
|
dbus_message_unref( msg );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dbusRunning( DBusConnection *conn, const char *player ) {
|
||||||
|
char *status = dbusStatus( conn, player );
|
||||||
|
bool ret = strcmp( status, "Playing" ) == 0;
|
||||||
|
ret |= strcmp( status, "Paused" ) == 0;
|
||||||
|
free( status );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dbusPlaying( DBusConnection *conn, const char *player ) {
|
||||||
|
char *status = dbusStatus( conn, player );
|
||||||
|
bool ret = strcmp( status, "Playing" ) == 0;
|
||||||
|
free( status );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ void dbusPlayPause( DBusConnection *conn, const char *player );
|
|||||||
void dbusNext( DBusConnection *conn, const char *player );
|
void dbusNext( DBusConnection *conn, const char *player );
|
||||||
void dbusPrev( DBusConnection *conn, const char *player );
|
void dbusPrev( DBusConnection *conn, const char *player );
|
||||||
void dbusStop( DBusConnection *conn, const char *player );
|
void dbusStop( DBusConnection *conn, const char *player );
|
||||||
bool dbusStatus( DBusConnection *conn, const char *player );
|
bool dbusRunning( DBusConnection *conn, const char *player );
|
||||||
|
bool dbusPlaying( DBusConnection *conn, const char *player );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
8
main.c
8
main.c
@ -60,7 +60,7 @@ int main( int argc, char **argv ) {
|
|||||||
|
|
||||||
if ( requests & SONG_FLAG || requests & META_FLAG ) {
|
if ( requests & SONG_FLAG || requests & META_FLAG ) {
|
||||||
struct song_metadata song = { 0 };
|
struct song_metadata song = { 0 };
|
||||||
if ( sources & MPD_FLAG ) {
|
if ( sources & MPD_FLAG && mpdPlaying( mpd_connection ) ) {
|
||||||
song = mpdGetSong( mpd_connection );
|
song = mpdGetSong( mpd_connection );
|
||||||
if ( requests & SONG_FLAG )
|
if ( requests & SONG_FLAG )
|
||||||
printSong( &song );
|
printSong( &song );
|
||||||
@ -70,6 +70,8 @@ int main( int argc, char **argv ) {
|
|||||||
|
|
||||||
if ( sources & DBUS_FLAG ) {
|
if ( sources & DBUS_FLAG ) {
|
||||||
for ( char **player = dbus_players; *player; ++player ) {
|
for ( char **player = dbus_players; *player; ++player ) {
|
||||||
|
if( !dbusPlaying( dbus_connection, *player ) )
|
||||||
|
continue;
|
||||||
song = dbusGetSong( dbus_connection, *player );
|
song = dbusGetSong( dbus_connection, *player );
|
||||||
if ( requests & SONG_FLAG )
|
if ( requests & SONG_FLAG )
|
||||||
printSong( &song );
|
printSong( &song );
|
||||||
@ -81,11 +83,11 @@ int main( int argc, char **argv ) {
|
|||||||
|
|
||||||
if( requests & RUNNING_FLAG ) {
|
if( requests & RUNNING_FLAG ) {
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
if( sources & MPD_FLAG && mpdStatus( mpd_connection ) )
|
if( sources & MPD_FLAG && mpdRunning( mpd_connection ) )
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
if( sources & DBUS_FLAG ) {
|
if( sources & DBUS_FLAG ) {
|
||||||
for( char **player = dbus_players; *player; ++player ) {
|
for( char **player = dbus_players; *player; ++player ) {
|
||||||
if( dbusStatus( dbus_connection, *player ) )
|
if( dbusRunning( dbus_connection, *player ) )
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
mpd_client.c
16
mpd_client.c
@ -65,11 +65,21 @@ void mpdStop( struct mpd_connection *mpd_connection ) {
|
|||||||
mpd_send_stop( mpd_connection );
|
mpd_send_stop( mpd_connection );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mpdStatus( struct mpd_connection *mpd_connection ) {
|
enum mpd_state mpdStatus( struct mpd_connection *mpd_connection ) {
|
||||||
struct mpd_status *status = mpd_run_status( mpd_connection );
|
struct mpd_status *status = mpd_run_status( mpd_connection );
|
||||||
if( status == NULL )
|
if( status == NULL )
|
||||||
return false;
|
return -1;
|
||||||
enum mpd_state ret = mpd_status_get_state( status );
|
enum mpd_state ret = mpd_status_get_state( status );
|
||||||
mpd_status_free( status );
|
mpd_status_free( status );
|
||||||
return ret != MPD_STATE_STOP && ret != MPD_STATE_UNKNOWN;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mpdRunning( struct mpd_connection *mpd_connection ) {
|
||||||
|
enum mpd_state state = mpdStatus( mpd_connection );
|
||||||
|
return state != MPD_STATE_STOP && state != MPD_STATE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mpdPlaying( struct mpd_connection *mpd_connection ) {
|
||||||
|
enum mpd_state state = mpdStatus( mpd_connection );
|
||||||
|
return state == MPD_STATE_PLAY;
|
||||||
}
|
}
|
||||||
|
@ -10,4 +10,5 @@ void mpdPlayPause( struct mpd_connection *mpd_connection );
|
|||||||
void mpdNext( struct mpd_connection *mpd_connection );
|
void mpdNext( struct mpd_connection *mpd_connection );
|
||||||
void mpdPrev( struct mpd_connection *mpd_connection );
|
void mpdPrev( struct mpd_connection *mpd_connection );
|
||||||
void mpdStop( struct mpd_connection *mpd_connection );
|
void mpdStop( struct mpd_connection *mpd_connection );
|
||||||
bool mpdStatus( struct mpd_connection *mpd_connection );
|
bool mpdRunning( struct mpd_connection *mpd_connection );
|
||||||
|
bool mpdPlaying( struct mpd_connection *mpd_connection );
|
||||||
|
Loading…
Reference in New Issue
Block a user