mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Media (Linux): detects song length & play position
This commit is contained in:
@@ -23,6 +23,8 @@ const FFMediaResult* ffDetectMedia(bool saveCover) {
|
||||
ffStrbufInit(&result.url);
|
||||
ffStrbufInit(&result.status);
|
||||
ffStrbufInit(&result.cover);
|
||||
result.length = 0;
|
||||
result.position = 0;
|
||||
result.removeCoverAfterUse = false;
|
||||
ffDetectMediaImpl(&result, saveCover);
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ typedef struct FFMediaResult {
|
||||
FFstrbuf url;
|
||||
FFstrbuf status;
|
||||
FFstrbuf cover;
|
||||
uint32_t length; // In milliseconds
|
||||
uint32_t position; // In milliseconds
|
||||
bool removeCoverAfterUse;
|
||||
} FFMediaResult;
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@ static bool parseMprisMetadata(FFDBusData* data, DBusMessageIter* rootIterator,
|
||||
break;
|
||||
}
|
||||
} else if (ffStrStartsWith(key, "mpris:")) {
|
||||
const char* xesam = key + strlen("mpris:");
|
||||
if (ffStrEquals(xesam, "artUrl")) {
|
||||
const char* mpris = key + strlen("mpris:");
|
||||
if (ffStrEquals(mpris, "artUrl")) {
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
ffDBusGetString(data, &dictIterator, &path);
|
||||
if (ffStrbufStartsWithS(&path, "file:///")) {
|
||||
@@ -94,6 +94,11 @@ static bool parseMprisMetadata(FFDBusData* data, DBusMessageIter* rootIterator,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ffStrEquals(mpris, "length")) {
|
||||
uint64_t length = 0; // microseconds
|
||||
if (ffDBusGetUint(data, &dictIterator, &length)) {
|
||||
result->length = (uint32_t) (length / 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +142,11 @@ static bool getBusProperties(FFDBusData* data, const char* busName, FFMediaResul
|
||||
parseMprisMetadata(data, &dictIterator, result);
|
||||
} else if (ffStrEquals(key, "PlaybackStatus")) {
|
||||
ffDBusGetString(data, &dictIterator, &result->status);
|
||||
} else if (ffStrEquals(key, "Position")) {
|
||||
int64_t position = 0; // microseconds
|
||||
if (ffDBusGetInt(data, &dictIterator, &position) && position > 0) {
|
||||
result->position = (uint32_t) (position / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
FF_DBUS_ITER_CONTINUE(data, &arrayIterator)
|
||||
|
||||
@@ -158,6 +158,8 @@ bool ffGenerateMediaJsonResult(FF_A_UNUSED FFMediaOptions* options, yyjson_mut_d
|
||||
yyjson_mut_obj_add_strbuf(doc, song, "artist", &media->artist);
|
||||
yyjson_mut_obj_add_strbuf(doc, song, "album", &media->album);
|
||||
yyjson_mut_obj_add_strbuf(doc, song, "status", &media->status);
|
||||
yyjson_mut_obj_add_uint(doc, song, "length", media->length);
|
||||
yyjson_mut_obj_add_uint(doc, song, "position", media->position);
|
||||
if (media->cover.length > 0) {
|
||||
yyjson_mut_obj_add_strbuf(doc, song, "cover", &media->cover);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user