Skip to content

Commit

Permalink
scripts: Add script azlyrics_dunst_fetcher.hs
Browse files Browse the repository at this point in the history
Haskell script called by dunst for Spotify notifcations to fetch lyrics
uppon request and send it as sequencial notifications splited in stazas

Signed-off-by: Jonathas-Conceicao <jadoliveira@inf.ufpel.edu.br>
  • Loading branch information
Jonathas-Conceicao committed Nov 7, 2019
1 parent 5bf6a18 commit 6f06194
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions scripts/azlyrics_dunst_fetcher.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/env runhaskell
import qualified System.Environment as Env
import qualified System.Process as Proc
import qualified Data.Char as CharUtil

lyricsAppId :: String
lyricsAppId = "750" -- sum of ASCII values for "Spotify" just for fun

main :: IO ()
main = do
args <- Env.getArgs
case args of
["Spotify", summary, body, _icon, urgency] -> do
response <- Proc.readProcess
"dunstify"
[ "-a", "AzLyrics"
, "-u", urgency
, "-r", lyricsAppId
, "-A", "azlyrics,default"
, summary, body
] []
case init response of
"azlyrics" -> notify_lyrics body summary
_ -> return ()
_ -> return ()

notify_lyrics :: String -> String -> IO ()
notify_lyrics artist song = do
Proc.callProcess
"dunstify"
[ "-a", "Lyrics"
, "-r", lyricsAppId
, "-t", "0"
, "-u", "LOW"
, artist ++ " - " ++ song, "Fetching..."
]
lyrics <- Proc.readProcess "azlyrics" [fixArtist artist, fixSong song] []
notify_blocks $ stanza lyrics
where
notify_blocks :: [String] -> IO ()
notify_blocks [] = return ()
notify_blocks (stanza: ss) = do
rep <- Proc.readProcess
"dunstify"
[ "-a", "Lyrics"
, "-r", lyricsAppId
, "-t", "0"
, "-u", "LOW"
, "-A", "continue,default"
, artist ++ " - " ++ song, stanza
] []
case init rep of
"continue" -> notify_blocks ss
_ -> return ()

stanza :: String -> [String]
stanza s = map unlines $ stanzaAux (lines s) []
where
stanzaAux :: [String] -> [String] -> [[String]]
stanzaAux [] ss = [ss]
stanzaAux ("": ls) ss = ss:(stanzaAux ls [])
stanzaAux (l: ls) ss = stanzaAux ls (ss++[l])

-- temporary workarround

fixArtist :: String -> String
fixArtist = map CharUtil.toLower . filter (/= ' ') . takeWhile ((||) <$> CharUtil.isAlphaNum <*> (' '==))

fixSong :: String -> String
fixSong = map CharUtil.toLower . filter CharUtil.isAlphaNum

0 comments on commit 6f06194

Please sign in to comment.