11#include "fastfetch.h"
22
3+ #include <ctype.h>
4+
35#define FF_SONG_MODULE_NAME "Song"
4- #define FF_SONG_NUM_FORMAT_ARGS 4
6+ #define FF_SONG_NUM_FORMAT_ARGS 5
7+
8+ static bool shouldIgoreChar (char c )
9+ {
10+ return isblank (c ) || c == '-' || c == '.' ;
11+ }
12+
13+ static bool artistInSongTitle (const FFstrbuf * song , const FFstrbuf * artist )
14+ {
15+ uint32_t artistIndex = 0 ;
16+ uint32_t songIndex = 0 ;
17+
18+ while (true)
19+ {
20+ while (shouldIgoreChar (song -> chars [songIndex ]))
21+ ++ songIndex ;
22+
23+ while (shouldIgoreChar (artist -> chars [artistIndex ]))
24+ ++ artistIndex ;
25+
26+ if (artist -> chars [artistIndex ] == '\0' )
27+ return true;
28+
29+ if (song -> chars [songIndex ] == '\0' )
30+ return false;
31+
32+ if (tolower (song -> chars [songIndex ]) != tolower (artist -> chars [artistIndex ]))
33+ return false;
34+
35+ ++ artistIndex ;
36+ ++ songIndex ;
37+ }
38+
39+ //Unreachable
40+ return false;
41+ }
542
643void ffPrintSong (FFinstance * instance )
744{
@@ -13,13 +50,39 @@ void ffPrintSong(FFinstance* instance)
1350 return ;
1451 }
1552
53+ FFstrbuf songPretty ;
54+ ffStrbufInitCopy (& songPretty , & media -> song );
55+ const char * removeStrings [] = {
56+ "(Official Music Video)" , "(Official Video)" , "(Music Video)" ,
57+ "[Official Music Video]" , "[Official Video]" , "[Music Video]" ,
58+ "| Official Music Video" , "| Official Video" , "| Music Video" ,
59+ "[Official Audio]" , "[Audio]" , "(Audio)" , "| Official Audio" , "| Audio" , "| OFFICIAL AUDIO" ,
60+ "(Lyric Video)" , "(Official Lyric Video)" , "(Lyrics)" ,
61+ "(dirty version)" , "(dirty)" , "(Clean)" , "(Clean Version)" ,
62+ };
63+ ffStrbufRemoveStringsA (& songPretty , sizeof (removeStrings ) / sizeof (removeStrings [0 ]), removeStrings );
64+ ffStrbufTrimRight (& songPretty , ' ' );
65+
66+ if (songPretty .length == 0 )
67+ ffStrbufAppend (& songPretty , & media -> song );
68+
1669 if (instance -> config .songFormat .length == 0 )
1770 {
71+ //We don't expose artistPretty to the format, as it might be empty (when the think that the artist is already in the song title)
72+ FFstrbuf artistPretty ;
73+ ffStrbufInitCopy (& artistPretty , & media -> artist );
74+ ffStrbufRemoveIgnCaseEndS (& artistPretty , " - Topic" );
75+ ffStrbufRemoveIgnCaseEndS (& artistPretty , "VEVO" );
76+ ffStrbufTrimRight (& artistPretty , ' ' );
77+
78+ if (artistInSongTitle (& songPretty , & artistPretty ))
79+ ffStrbufClear (& artistPretty );
80+
1881 ffPrintLogoAndKey (instance , FF_SONG_MODULE_NAME , 0 , & instance -> config .songKey );
1982
20- if (media -> artist .length > 0 )
83+ if (artistPretty .length > 0 )
2184 {
22- ffStrbufWriteTo (& media -> artist , stdout );
85+ ffStrbufWriteTo (& artistPretty , stdout );
2386 fputs (" - " , stdout );
2487 }
2588
@@ -29,11 +92,12 @@ void ffPrintSong(FFinstance* instance)
2992 fputs (" - " , stdout );
3093 }
3194
32- ffStrbufPutTo (& media -> song , stdout );
95+ ffStrbufPutTo (& songPretty , stdout );
3396 }
3497 else
3598 {
3699 ffPrintFormatString (instance , FF_SONG_MODULE_NAME , 0 , & instance -> config .songKey , & instance -> config .songFormat , NULL , FF_SONG_NUM_FORMAT_ARGS , (FFformatarg []){
100+ {FF_FORMAT_ARG_TYPE_STRBUF , & songPretty },
37101 {FF_FORMAT_ARG_TYPE_STRBUF , & media -> song },
38102 {FF_FORMAT_ARG_TYPE_STRBUF , & media -> artist },
39103 {FF_FORMAT_ARG_TYPE_STRBUF , & media -> album },
0 commit comments