This repository has been archived by the owner on Jul 11, 2018. It is now read-only.
-
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.
- Loading branch information
Showing
11 changed files
with
189 additions
and
62 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,7 @@ | ||
Copyright (C) 2012 Dmitry Malikov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,41 @@ | ||
Name: Loh | ||
Version: 0.0.0 | ||
Category: Network | ||
Description: LastFMScrobbler on Haskell | ||
Synopsis: LastFMScrobbler on Haskell | ||
|
||
License: MIT | ||
License-file: LICENSE | ||
|
||
Author: Dmitry Malikov | ||
|
||
Maintainer: Dmitry Malikov <[email protected]> | ||
|
||
Build-type: Simple | ||
Cabal-version: >= 1.6 | ||
Homepage: - | ||
|
||
Library | ||
Build-Depends: base >= 3 && < 5, | ||
containers, | ||
directory, | ||
filepath, | ||
libmpd == 0.7.2, | ||
liblastfm, | ||
mtl, | ||
old-locale, | ||
process, | ||
split, | ||
time, | ||
transformers | ||
|
||
|
||
HS-Source-Dirs: src, src/Mocp | ||
|
||
Exposed-Modules: Loh.Types, | ||
Loh.DB, | ||
Loh.Player, | ||
Loh.Scrobbler | ||
Mocp | ||
|
||
GHC-Options: -Wall |
Empty file.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
{-# LANGUAGE UnicodeSyntax #-} | ||
module Loh where | ||
|
||
import Control.Applicative ((<$>), (<*>)) | ||
import Data.Char (isSpace) | ||
import Data.List.Split (splitOn) | ||
import Data.Maybe | ||
import System.Directory (getHomeDirectory) | ||
import System.FilePath ((</>)) | ||
|
||
import qualified Network.Lastfm as LFM | ||
|
||
configFilePath ∷ FilePath | ||
configFilePath = ".lastfm.conf" | ||
|
||
getConfig ∷ IO (LFM.APIKey, LFM.SessionKey, LFM.Secret) | ||
getConfig = do | ||
configContent ← readFile <$> (</> configFilePath) <$> getHomeDirectory | ||
values ← map ((\[x,y] -> (x,y)) . splitOn "=" . filter (not . isSpace)) . lines <$> configContent | ||
return $ fromMaybe (error "Config at ~/.lastfm.conf should contain APIKey, SessionKey and Secret") (readConfig values) | ||
where | ||
readConfig xs = (,,) <$> (LFM.APIKey <$> lookup "APIKey" xs) <*> (LFM.SessionKey <$> lookup "SessionKey" xs) <*> (LFM.Secret <$> lookup "Secret" xs) | ||
|
||
|
||
main ∷ IO () | ||
main = |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{-# LANGUAGE UnicodeSyntax #-} | ||
module Loh.DB | ||
( clear | ||
, getDB | ||
|
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,53 @@ | ||
{-# LANGUAGE UnicodeSyntax #-} | ||
module Loh.Player where | ||
|
||
import Control.Applicative ((<$>)) | ||
import Data.Maybe (fromJust, fromMaybe, isJust) | ||
|
||
import Loh.Types | ||
|
||
import qualified Data.Map as M | ||
import qualified Mocp as MOC | ||
import qualified Network.MPD as MPD | ||
|
||
getMocpInfo ∷ IO (Maybe TrackInfo) | ||
getMocpInfo = do | ||
mocpResponse ← MOC.mocp | ||
return $ case mocpResponse of | ||
Right (MOC.MocpInfo MOC.Playing (Just s)) → Just TrackInfo | ||
{ artist = MOC.artist $ MOC.metadata s | ||
, album = MOC.album $ MOC.metadata s | ||
, duration = (fromIntegral (MOC.currentSec s)) / (fromIntegral (MOC.totalSec s)) | ||
, track = MOC.track $ MOC.metadata s | ||
} | ||
_ → Nothing | ||
|
||
getMpdInfo ∷ IO (Maybe TrackInfo) | ||
getMpdInfo = do | ||
maybeSong ← MPD.withMPD MPD.currentSong | ||
status ← MPD.withMPD MPD.status | ||
return $ case status of | ||
Right _ → case MPD.stState <$> status of | ||
Right MPD.Playing → case maybeSong of | ||
Right (Just song) → case MPD.stTime <$> status of | ||
Right (curTime, totalTime) → | ||
Just TrackInfo | ||
{ artist = fromMaybe "No Artist" $ head <$> M.lookup MPD.Artist tag | ||
, album = fromMaybe "No Album" $ head <$> M.lookup MPD.Album tag | ||
, duration = curTime / (fromIntegral totalTime) | ||
, track = fromMaybe "No Track" $ head <$> M.lookup MPD.Track tag | ||
} where tag = MPD.sgTags song | ||
_ → Nothing | ||
_ → Nothing | ||
_ → Nothing | ||
_ → Nothing | ||
|
||
getPlayersInfo ∷ IO PlayersInfo | ||
getPlayersInfo = do | ||
maybeMpdInfo ← getMpdInfo | ||
maybeMocpInfo ← getMocpInfo | ||
return . M.fromList . catMaybeSnd $ | ||
[ (Mpd, maybeMpdInfo) | ||
, (Mocp, maybeMocpInfo) | ||
] | ||
where catMaybeSnd = map (\(f,s) -> (f, fromJust s)) . filter (isJust . snd) |
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
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
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