mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Make media detection more robust
This commit is contained in:
+5
-3
@@ -31,6 +31,8 @@ __fastfetch_complete_help()
|
||||
"datetime-format"
|
||||
"date-format"
|
||||
"time-format"
|
||||
"media-format"
|
||||
"player-format"
|
||||
)
|
||||
COMPREPLY=($(compgen -W "${__ff_helps[*]}" -- "$CURRENT_WORD"))
|
||||
}
|
||||
@@ -215,8 +217,8 @@ __fastfetch_completion()
|
||||
"--public-ip-key"
|
||||
"--player-format"
|
||||
"--player-key"
|
||||
"--song-format"
|
||||
"--song-key"
|
||||
"--media-format"
|
||||
"--media-key"
|
||||
"--datetime-key"
|
||||
"--datetime-format"
|
||||
"--date-format"
|
||||
@@ -257,7 +259,7 @@ __fastfetch_completion()
|
||||
"--local-ip-error"
|
||||
"--public-ip-error"
|
||||
"--player-error"
|
||||
"--song-error"
|
||||
"--media-error"
|
||||
"--datetime-error"
|
||||
"--date-error"
|
||||
"--time-error"
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@
|
||||
--memory-format Used: {}; Total: {}; Percentage: {}
|
||||
--disk-format Used: {}; Total: {}; Files: {}; Percentage: {}
|
||||
--battery-format Manufactor: {}; Model: {}; Technology: {}; Capacity: {}; Status: {}
|
||||
--player-format Name: {}
|
||||
--song-format Song: {}; Artist: {}; Album: {}
|
||||
--player-format Pretty: {}; Name: {}; Bus: {}; Url: {}
|
||||
--media-format Pretty: {}; Name: {}; Artist: {}; Album: {}
|
||||
--datetime-format year: {}; yearShort: {}; month: {}; monthPretty: {}; monthName: {}; monthNameShort: {}; weekNumber: {}; weekday: {}; weekdayShort: {}; dayInYear: {}; dayInMonth: {}; dayInWeek: {}; hour: {}; hourPretty: {}; hour12: {}; hour12Pretty: {}; minute: {}; minutePretty: {}; second: {}; secondPretty: {}
|
||||
--vulkan-format driver: {}; Api Version: {}; Conformance Version: {}
|
||||
--opengl-format version: {}; renderer: {}; vendor: {}
|
||||
|
||||
+16
-17
@@ -203,7 +203,7 @@ static bool getBusProperties(const char* busName, FFMediaResult* result, DBusDat
|
||||
else if(strcmp(key, "xesam:url") == 0)
|
||||
getValue(&dictIterator, &result->url, data);
|
||||
|
||||
if(result->song.length > 0 && result->artist.length > 0 && result->album.length > 0)
|
||||
if(result->song.length > 0 && result->artist.length > 0 && result->album.length > 0 && result->url.length > 0)
|
||||
break;
|
||||
|
||||
FF_DBUS_ITER_CONTINUE(arrayIterator)
|
||||
@@ -219,12 +219,15 @@ static bool getBusProperties(const char* busName, FFMediaResult* result, DBusDat
|
||||
return false;
|
||||
}
|
||||
|
||||
//Set short bus name
|
||||
ffStrbufAppendS(&result->busNameShort, busName + sizeof(FF_DBUS_MPRIS_PREFIX) - 1);
|
||||
|
||||
//We found a song, get the player name
|
||||
|
||||
getPropertyString(busName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2", "Identity", &result->player, data);
|
||||
|
||||
if(result->player.length == 0)
|
||||
getPropertyString(busName, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2", "DesktopEntry", &result->player, data);
|
||||
if(result->player.length == 0)
|
||||
ffStrbufAppend(&result->player, &result->busNameShort);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -233,13 +236,10 @@ static void getCustomBus(FFinstance* instance, FFMediaResult* result, DBusData*
|
||||
{
|
||||
if(ffStrbufStartsWithS(&instance->config.playerName, FF_DBUS_MPRIS_PREFIX))
|
||||
{
|
||||
ffStrbufAppendS(&result->busNameShort, instance->config.playerName.chars + sizeof(FF_DBUS_MPRIS_PREFIX) - 1);
|
||||
getBusProperties(instance->config.playerName.chars, result, data);
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufAppend(&result->busNameShort, &instance->config.playerName);
|
||||
|
||||
FFstrbuf busName;
|
||||
ffStrbufInit(&busName);
|
||||
ffStrbufAppendS(&busName, FF_DBUS_MPRIS_PREFIX);
|
||||
@@ -250,6 +250,12 @@ static void getCustomBus(FFinstance* instance, FFMediaResult* result, DBusData*
|
||||
|
||||
static void getBestBus(FFMediaResult* result, DBusData* data)
|
||||
{
|
||||
if(
|
||||
getBusProperties(FF_DBUS_MPRIS_PREFIX"spotify", result, data) ||
|
||||
getBusProperties(FF_DBUS_MPRIS_PREFIX"vlc", result, data) ||
|
||||
getBusProperties(FF_DBUS_MPRIS_PREFIX"plasma-browser-integration", result, data)
|
||||
) return;
|
||||
|
||||
DBusMessage* message = data->ffdbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames");
|
||||
if(message == NULL)
|
||||
return;
|
||||
@@ -277,10 +283,7 @@ static void getBestBus(FFMediaResult* result, DBusData* data)
|
||||
FF_DBUS_ITER_CONTINUE(arrayIterator)
|
||||
|
||||
if(getBusProperties(busName, result, data))
|
||||
{
|
||||
ffStrbufAppendS(&result->busNameShort, busName + sizeof(FF_DBUS_MPRIS_PREFIX) - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
FF_DBUS_ITER_CONTINUE(arrayIterator)
|
||||
}
|
||||
@@ -352,19 +355,15 @@ const FFMediaResult* ffDetectMedia(FFinstance* instance)
|
||||
getMedia(instance, &result);
|
||||
#endif
|
||||
|
||||
//Set busNameShort if a custom player was given, but loading dbus failed
|
||||
if(instance->config.playerName.length > 0 && result.busNameShort.length == 0)
|
||||
//Set player if a custom player was given, but loading with dbus failed
|
||||
if(instance->config.playerName.length > 0 && result.song.length == 0)
|
||||
{
|
||||
if(ffStrbufStartsWithS(&instance->config.playerName, FF_DBUS_MPRIS_PREFIX))
|
||||
ffStrbufAppendS(&result.busNameShort, instance->config.playerName.chars + sizeof(FF_DBUS_MPRIS_PREFIX) - 1);
|
||||
ffStrbufAppendS(&result.player, instance->config.playerName.chars + sizeof(FF_DBUS_MPRIS_PREFIX) - 1);
|
||||
else
|
||||
ffStrbufAppend(&result.busNameShort, &instance->config.playerName);
|
||||
ffStrbufAppend(&result.player, &instance->config.playerName);
|
||||
}
|
||||
|
||||
//Set player to busNameShort, if detection failed
|
||||
if(result.player.length == 0)
|
||||
ffStrbufAppend(&result.player, &result.busNameShort);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
+11
-11
@@ -329,20 +329,20 @@ static inline void printCommandHelp(const char* command)
|
||||
}
|
||||
else if(strcasecmp(command, "player-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("player", "{}", 3,
|
||||
constructAndPrintCommandHelpFormat("player", "{}", 4,
|
||||
"Pretty player name",
|
||||
"Player name",
|
||||
"DBus bus name"
|
||||
"DBus bus name",
|
||||
"URL name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "song-format") == 0)
|
||||
else if(strcasecmp(command, "song-format") == 0 || strcasecmp(command, "media-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("song", "{3} - {4} - {1}", 5,
|
||||
"Song name pretty",
|
||||
"Song name",
|
||||
constructAndPrintCommandHelpFormat("song", "{3} - {1}", 4,
|
||||
"Pretty media name",
|
||||
"Media name",
|
||||
"Artist name",
|
||||
"Album name",
|
||||
"Song url"
|
||||
"Album name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "datetime-format") == 0 || strcasecmp(command, "date-format") == 0 || strcasecmp(command, "time-format") == 0)
|
||||
@@ -1132,11 +1132,11 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.player.outputFormat);
|
||||
else if(strcasecmp(key, "--player-error") == 0)
|
||||
optionParseString(key, value, &instance->config.player.errorFormat);
|
||||
else if(strcasecmp(key, "--song-key") == 0)
|
||||
else if(strcasecmp(key, "--song-key") == 0 || strcasecmp(key, "--media-key") == 0)
|
||||
optionParseString(key, value, &instance->config.song.key);
|
||||
else if(strcasecmp(key, "--song-format") == 0)
|
||||
else if(strcasecmp(key, "--song-format") == 0 || strcasecmp(key, "--media-format") == 0)
|
||||
optionParseString(key, value, &instance->config.song.outputFormat);
|
||||
else if(strcasecmp(key, "--song-error") == 0)
|
||||
else if(strcasecmp(key, "--song-error") == 0 || strcasecmp(key, "--media-error") == 0)
|
||||
optionParseString(key, value, &instance->config.song.errorFormat);
|
||||
else if(strcasecmp(key, "--datetime-key") == 0)
|
||||
optionParseString(key, value, &instance->config.dateTime.key);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#define FF_PLAYER_MODULE_NAME "Media Player"
|
||||
#define FF_PLAYER_NUM_FORMAT_ARGS 3
|
||||
#define FF_PLAYER_NUM_FORMAT_ARGS 4
|
||||
|
||||
void ffPrintPlayer(FFinstance* instance)
|
||||
{
|
||||
@@ -62,7 +62,8 @@ void ffPrintPlayer(FFinstance* instance)
|
||||
ffPrintFormat(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player, FF_PLAYER_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &playerPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->player},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->busNameShort}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->busNameShort},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->url}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -5,7 +5,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#define FF_SONG_MODULE_NAME "Media"
|
||||
#define FF_SONG_NUM_FORMAT_ARGS 5
|
||||
#define FF_SONG_NUM_FORMAT_ARGS 4
|
||||
|
||||
static bool shouldIgoreChar(char c)
|
||||
{
|
||||
@@ -97,8 +97,7 @@ void ffPrintSong(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &songPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->song},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->artist},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->album},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->url}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->album}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user