Add duration and position to meatadata

This commit is contained in:
zvon 2020-05-29 21:59:14 +02:00
parent d94fa07ec2
commit e68aa6f457
5 changed files with 27 additions and 0 deletions

View File

@ -158,10 +158,22 @@ struct song_metadata dbusGetSong( DBusConnection *conn, const char *player ) {
ret.file = strdup( meta_val );
else if ( !strcmp( meta_name, "mpris:artUrl" ) )
ret.art_uri = strdup( meta_val );
} else if ( dbus_message_iter_get_arg_type( &variant ) ==
DBUS_TYPE_INT64 ) {
if ( !strcmp( meta_name, "mpris:length" ) ) {
dbus_message_iter_get_basic( &variant, &ret.duration );
}
}
} while ( dbus_message_iter_next( &dict ) );
dbus_message_unref( msg );
const char *params2[3] = { "org.mpris.MediaPlayer2.Player", "Position",
NULL };
dbusQuery( &args, &msg, conn, player, "/org/mpris/MediaPlayer2",
"org.freedesktop.DBus.Properties", "Get", params2 );
dbus_message_iter_recurse( &args, &variant );
dbus_message_iter_get_basic( &variant, &ret.position );
return ret;
}

View File

@ -21,6 +21,8 @@ void printMeta( struct song_metadata *song ) {
if ( song->art_uri != NULL ) {
printf( "ART: %s\n", song->art_uri );
}
printf( "DURATION: %zu\n", song->duration );
printf( "POSITION: %zu\n", song->position );
}
void freeSong( struct song_metadata *song ) {

View File

@ -1,6 +1,8 @@
#ifndef METADATA_H
#define METADATA_H
#include <stdlib.h>
struct song_metadata {
const char *title;
const char *artist;
@ -8,6 +10,8 @@ struct song_metadata {
const char *year;
const char *file;
const char *art_uri;
size_t duration;
size_t position;
};
void printSong( struct song_metadata *song );

View File

@ -43,6 +43,14 @@ struct song_metadata mpdGetSong( struct mpd_connection *mpd_connection ) {
ret.year = strdup( copy );
ret.file = strdup( mpd_song_get_uri( song ) );
struct mpd_status *status = mpd_run_status( mpd_connection );
if ( status == NULL )
goto endfree;
ret.duration = mpd_status_get_total_time( status );
ret.position = mpd_status_get_elapsed_time( status );
mpd_status_free( status );
endfree:
mpd_song_free( song );
end:

View File

@ -1,5 +1,6 @@
#include <mpd/connection.h>
#include <stdbool.h>
#include <stdlib.h>
#include "metadata.h"