mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 08:13:44 +01:00
Player: JSON format support
This commit is contained in:
@@ -75,7 +75,7 @@ void ffPrintPlayer(FFPlayerOptions* options)
|
||||
|
||||
void ffInitPlayerOptions(FFPlayerOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, ffGeneratePlayerJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -110,3 +110,19 @@ void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_PLAYER_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGeneratePlayerJson(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
const FFMediaResult* media = ffDetectMedia();
|
||||
|
||||
if(media->error.length > 0)
|
||||
{
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "error", &media->error);
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "player", &media->player);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "playerId", &media->playerId);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "url", &media->url);
|
||||
}
|
||||
|
||||
@@ -10,3 +10,4 @@ void ffInitPlayerOptions(FFPlayerOptions* options);
|
||||
bool ffParsePlayerCommandOptions(FFPlayerOptions* options, const char* key, const char* value);
|
||||
void ffDestroyPlayerOptions(FFPlayerOptions* options);
|
||||
void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module);
|
||||
void ffGeneratePlayerJson(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user