From 93130003e9ad6b0235fc7c09f1c0928d4e5a3d6c Mon Sep 17 00:00:00 2001 From: Thomas Bleher Date: Wed, 2 Dec 2020 11:01:24 +0100 Subject: [PATCH] Allow giving the filename with extension in play commands (#237) Since commit 8e49687 ("Allow referencing audio files with filenames outside [a-zA-Z0-9_] (#236)"), all filenames could be given to the play command, however the user had to cut off the file extension manually. First search for the full filename, before trying with the standard extension. To allow basic filenames without quoting, "." is now also allowed in identifiers for the play command. Idea and code suggestion by Joachim Breitner. Co-authored-by: Thomas Bleher --- Changelog.md | 3 ++- src/TipToiYaml.hs | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 724afb5e..f38e5c03 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,7 +3,8 @@ ## 1.10 (UNRELEASED) * Audio filenames can now be quoted, to support filenames with characters - outside the range `a-zA-Z0-9_` + outside the range `a-zA-Z0-9_`. Audio files can also be given including + their extension. * Support for the `stop` and `restart` codes (generated by default) * The `set-language` command truncates long language names (like `ITALIAN`) automatically. diff --git a/src/TipToiYaml.hs b/src/TipToiYaml.hs index 11c554de..8939fe8e 100644 --- a/src/TipToiYaml.hs +++ b/src/TipToiYaml.hs @@ -843,11 +843,9 @@ ttYaml2tt no_date dir (TipToiYAML {..}) extCodes = do Just (lang, txt) -> do Right <$> readFile' (ttsFileName lang txt) Nothing -> do - let paths = [ combine dir relpath - | ext <- map snd fileMagics - , let pat = fromMaybe "%s" ttyMedia_Path - , let relpath = printf pat fn <.> ext - ] + let pat = fromMaybe "%s" ttyMedia_Path + let basePath = printf pat fn + let paths = map (combine dir) (basePath : [basePath <.> ext | (_,ext) <- fileMagics ]) ex <- filterM doesFileExist paths case ex of [] -> do @@ -955,7 +953,7 @@ parsePlayList :: Parser [String] parsePlayList = P.commaSep lexer $ parseAudioRef parseAudioRef :: Parser String -parseAudioRef = (P.lexeme lexer $ many1 (alphaNum <|> char '_')) <|> P.stringLiteral lexer +parseAudioRef = (P.lexeme lexer $ many1 (alphaNum <|> char '_' <|> char '.')) <|> P.stringLiteral lexer parseScriptRef :: Parser String parseScriptRef = P.lexeme lexer $ many1 (alphaNum <|> char '_')