-
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
9 changed files
with
123 additions
and
28 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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
module Main where | ||
|
||
import Data.String.Strip | ||
import Args | ||
import Options.Applicative (execParser) | ||
|
||
main :: IO () | ||
main = interact strip | ||
main = execParser app >>= run | ||
|
||
run :: Args -> IO () | ||
run = putStrLn . show |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Args where | ||
|
||
import Options.Applicative | ||
import Data.Semigroup ((<>)) | ||
import Text.Regex (mkRegex, splitRegex) | ||
import Attributes | ||
|
||
data Args = Args { | ||
source :: String | ||
, target :: String | ||
, attributes :: [Attribute] | ||
} | ||
deriving (Show, Eq) | ||
|
||
getArgs :: Parser Args | ||
getArgs = Args | ||
<$> strOption | ||
( long "source" <> | ||
short 's' <> | ||
help "Root of existing library") | ||
<*> strOption | ||
( long "target" <> | ||
short 't' <> | ||
help "Root of new library") | ||
<*> attrList | ||
|
||
attrList :: Parser [Attribute] | ||
attrList = option (maybeReader attrList) ( | ||
long "attributes" <> | ||
short 'a' <> | ||
help "comma-separated list of orderedf attributes for building directory tree") | ||
where attrList = sequence . (fmap toAttribute) . (splitRegex (mkRegex ",")) | ||
helpString = "comma-separated list of ordered attributes for building directory tree. Chosen from artist, title, album, year, track, composer" | ||
|
||
app :: ParserInfo Args | ||
app = info (getArgs <**> helper) | ||
( fullDesc | ||
<> progDesc "Copies an iTunes music library to a new directory tree built from the ID3 tag hierarchy provided" | ||
<> header "Make your music library make sense" ) |
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,34 @@ | ||
module Attributes where | ||
|
||
import Data.Accessor | ||
import ID3.Simple | ||
import ID3.Type | ||
|
||
data Attribute = Artist | ||
| Title | ||
| Album | ||
| Year | ||
| Track | ||
| Composer | ||
deriving (Show, Eq) | ||
|
||
toAttribute :: String -> Maybe Attribute | ||
toAttribute "artist" = Just Artist | ||
toAttribute "title" = Just Title | ||
toAttribute "album" = Just Album | ||
toAttribute "year" = Just Year | ||
toAttribute "track" = Just Track | ||
toAttribute "composer" = Just Composer | ||
toAttribute _ = Nothing | ||
|
||
getAttribute :: Tag -> Attribute -> Maybe String | ||
getAttribute tag Artist = getArtist tag | ||
getAttribute tag Title = getTitle tag | ||
getAttribute tag Year = getYear tag | ||
getAttribute tag Track = getTrack tag | ||
getAttribute tag Composer = getFrameText "TCOM" tag | ||
|
||
getFrameText :: FrameID -> Tag -> Maybe String | ||
getFrameText frid tag = case tag^.frame frid of | ||
Nothing -> Nothing | ||
Just fr -> Just (fr^.textContent) |
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 @@ | ||
module Itunes where |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module ArgsSpec where | ||
|
||
import Test.Hspec | ||
import Options.Applicative | ||
import Attributes | ||
import Args | ||
|
||
spec = do | ||
describe "parsing arguments" $ do | ||
it "parses properly supplied short arguments" $ do | ||
getParseResult ( | ||
execParserPure defaultPrefs app [ "-s" | ||
, "/Users/shterrett/iTunesMusic" | ||
, "-t" | ||
, "/Users/shterrett/music" | ||
, "-a" | ||
, "composer,album,artist" | ||
]) | ||
`shouldBe` (Just $ Args "/Users/shterrett/iTunesMusic" | ||
"/Users/shterrett/music" | ||
[Composer, Album, Artist]) | ||
it "parses properly supplied long arguments" $ do | ||
getParseResult ( | ||
execParserPure defaultPrefs app [ "--source" | ||
, "/Users/shterrett/iTunesMusic" | ||
, "--target" | ||
, "/Users/shterrett/music" | ||
, "--attributes" | ||
, "composer,album,artist" | ||
]) | ||
`shouldBe` (Just $ Args "/Users/shterrett/iTunesMusic" | ||
"/Users/shterrett/music" | ||
[Composer, Album, Artist]) |
This file was deleted.
Oops, something went wrong.