-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: Add script azlyrics_dunst_fetcher.hs
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
1 parent
5bf6a18
commit 6f06194
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |