Skip to content

Commit 9313000

Browse files
tbleherThomas Bleher
andauthored
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 <[email protected]>
1 parent 0441235 commit 9313000

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## 1.10 (UNRELEASED)
44

55
* Audio filenames can now be quoted, to support filenames with characters
6-
outside the range `a-zA-Z0-9_`
6+
outside the range `a-zA-Z0-9_`. Audio files can also be given including
7+
their extension.
78
* Support for the `stop` and `restart` codes (generated by default)
89
* The `set-language` command truncates long language names (like `ITALIAN`)
910
automatically.

src/TipToiYaml.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,9 @@ ttYaml2tt no_date dir (TipToiYAML {..}) extCodes = do
843843
Just (lang, txt) -> do
844844
Right <$> readFile' (ttsFileName lang txt)
845845
Nothing -> do
846-
let paths = [ combine dir relpath
847-
| ext <- map snd fileMagics
848-
, let pat = fromMaybe "%s" ttyMedia_Path
849-
, let relpath = printf pat fn <.> ext
850-
]
846+
let pat = fromMaybe "%s" ttyMedia_Path
847+
let basePath = printf pat fn
848+
let paths = map (combine dir) (basePath : [basePath <.> ext | (_,ext) <- fileMagics ])
851849
ex <- filterM doesFileExist paths
852850
case ex of
853851
[] -> do
@@ -955,7 +953,7 @@ parsePlayList :: Parser [String]
955953
parsePlayList = P.commaSep lexer $ parseAudioRef
956954

957955
parseAudioRef :: Parser String
958-
parseAudioRef = (P.lexeme lexer $ many1 (alphaNum <|> char '_')) <|> P.stringLiteral lexer
956+
parseAudioRef = (P.lexeme lexer $ many1 (alphaNum <|> char '_' <|> char '.')) <|> P.stringLiteral lexer
959957

960958
parseScriptRef :: Parser String
961959
parseScriptRef = P.lexeme lexer $ many1 (alphaNum <|> char '_')

0 commit comments

Comments
 (0)