mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
fix(spotify): parse information correctly for PWA on Windows
resolves #3310
This commit is contained in:
parent
b8c09f92ab
commit
39594b0d34
|
@ -11,30 +11,43 @@ func (s *Spotify) Enabled() bool {
|
|||
// Can be either "Spotify xxx" or the song name "Candlemass - Spellbreaker"
|
||||
windowTitle, err := s.env.QueryWindowTitles("spotify.exe", `^(Spotify.*)|(.*\s-\s.*)$`)
|
||||
if err == nil {
|
||||
return s.parseSpotifyTitle(windowTitle, " - ")
|
||||
return s.parseNativeTitle(windowTitle)
|
||||
}
|
||||
windowTitle, err = s.env.QueryWindowTitles("msedge.exe", `^(Spotify.*)`)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return s.parseWebSpotifyTitle(windowTitle)
|
||||
return s.parseWebTitle(windowTitle)
|
||||
}
|
||||
|
||||
func (s *Spotify) parseWebSpotifyTitle(windowTitle string) bool {
|
||||
windowTitle = strings.TrimPrefix(windowTitle, "Spotify - ")
|
||||
return s.parseSpotifyTitle(windowTitle, " • ")
|
||||
}
|
||||
func (s *Spotify) parseNativeTitle(windowTitle string) bool {
|
||||
separator := " - "
|
||||
|
||||
func (s *Spotify) parseSpotifyTitle(windowTitle, separator string) bool {
|
||||
if !strings.Contains(windowTitle, separator) {
|
||||
s.Status = stopped
|
||||
return false
|
||||
}
|
||||
|
||||
infos := strings.Split(windowTitle, separator)
|
||||
s.Artist = infos[0]
|
||||
// remove first element and concat others(a song can contains also a " - ")
|
||||
s.Track = strings.Join(infos[1:], separator)
|
||||
index := strings.Index(windowTitle, separator)
|
||||
s.Artist = windowTitle[0:index]
|
||||
s.Track = windowTitle[index+len(separator):]
|
||||
s.Status = playing
|
||||
s.resolveIcon()
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Spotify) parseWebTitle(windowTitle string) bool {
|
||||
windowTitle = strings.TrimPrefix(windowTitle, "Spotify - ")
|
||||
separator := " • "
|
||||
|
||||
if !strings.Contains(windowTitle, separator) {
|
||||
s.Status = stopped
|
||||
return false
|
||||
}
|
||||
|
||||
index := strings.Index(windowTitle, separator)
|
||||
s.Track = windowTitle[0:index]
|
||||
s.Artist = windowTitle[index+len(separator):]
|
||||
s.Status = playing
|
||||
s.resolveIcon()
|
||||
return true
|
||||
|
|
|
@ -63,10 +63,16 @@ func TestSpotifyWindowsPWA(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
Case: "Playing",
|
||||
ExpectedString: "\ue602 Snow in Stockholm - Sarah, the Illstrumentalist",
|
||||
ExpectedString: "\ue602 Sarah, the Illstrumentalist - Snow in Stockholm",
|
||||
ExpectedEnabled: true,
|
||||
Title: "Spotify - Snow in Stockholm • Sarah, the Illstrumentalist",
|
||||
},
|
||||
{
|
||||
Case: "Playing",
|
||||
ExpectedString: "\ue602 Main one - Bring the drama",
|
||||
ExpectedEnabled: true,
|
||||
Title: "Spotify - Bring the drama • Main one",
|
||||
},
|
||||
{
|
||||
Case: "Stopped",
|
||||
ExpectedEnabled: false,
|
||||
|
|
Loading…
Reference in a new issue