musicScroll 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+25/−19 lines, 3 files
Files
- CHANGELOG.md +5/−1
- musicScroll.cabal +1/−1
- src/MusicScroll/AZLyrics.hs +19/−17
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for music-scroll -## 0.1.0.0 -- YYYY-mm-dd+## 0.1.1.0 -- 2020-01-22++* Signal when the song couldn't be gotten from a lyrics website.++## 0.1.0.0 -- 2020-01-17 * First version. Released on an unsuspecting world.
musicScroll.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/ name: musicScroll-version: 0.1.0.0+version: 0.1.1.0 synopsis: Supply your tunes info without leaving your music player. description: Automatically retrive the lyrics of of your current song on SMPlayer and update it on each change. See the
src/MusicScroll/AZLyrics.hs view
@@ -1,16 +1,17 @@-{-# language OverloadedStrings, DataKinds, NamedFieldPuns #-}+{-# language OverloadedStrings, DataKinds, NamedFieldPuns, TypeApplications #-} module MusicScroll.AZLyrics (lyricsThread) where -import Control.Concurrent.STM (atomically)-import Control.Concurrent.STM.TBQueue (TBQueue, readTBQueue,- writeTBQueue)-import Control.Monad (forever)-import Data.Text (Text)-import Data.Text as T hiding (filter, tail, map)-import Data.Text.Encoding (decodeUtf8)-import MusicScroll.TrackInfo (TrackInfo(..), cleanTrack)-import MusicScroll.TagParsing-import Network.HTTP.Req+import Control.Concurrent.STM (atomically)+import Control.Concurrent.STM.TBQueue (TBQueue, readTBQueue, writeTBQueue)+import Control.Exception (try, SomeException)+import Control.Monad (forever)+import Data.Either (fromRight)+import Data.Text (Text)+import Data.Text as T hiding (filter, tail, map)+import Data.Text.Encoding (decodeUtf8)+import MusicScroll.TrackInfo (TrackInfo(..), cleanTrack)+import MusicScroll.TagParsing+import Network.HTTP.Req lyricsThread :: TBQueue TrackInfo -> TBQueue (TrackInfo, [Text]) -> IO a lyricsThread input output = forever $@@ -21,12 +22,13 @@ lyricsPipeline :: TrackInfo -> IO [Text] lyricsPipeline (TrackInfo {tArtist, tTitle}) = do let songUrl = url tArtist tTitle- resp <- getPage songUrl- if responseStatusCode resp /= 200- then return [ "Fallo AZLyrics" ]- else- do let body = decodeUtf8 (responseBody resp) -- can throw, decode header?- return (extractLyricsFromPage body)+ resp <- try @SomeException (getPage songUrl)+ let notValid = either (const True)+ ((/= 200) . responseStatusCode) resp+ if notValid then return [ "I failed at getting the lyrics!" ]+ else let Right realResp = resp+ body = decodeUtf8 (responseBody realResp)+ in return (extractLyricsFromPage body) getPage :: Url 'Https -> IO BsResponse getPage url = runReq defaultHttpConfig $