Skip to content

Commit

Permalink
Fix: Handle Non-ascii Unicode characters in ffprobe output
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthi-chaud committed Aug 10, 2024
1 parent 8c448fb commit 7019816
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/FFProbe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module FFProbe (
) where

import Data.Aeson (FromJSON, eitherDecodeStrict)
import Data.ByteString.Char8 (pack)
import Data.Text (pack)
import Data.Text.Encoding (encodeUtf8)
import FFProbe.Data.Chapter (Chapter)
import FFProbe.Data.Format (Format)
import FFProbe.Data.Stream (Stream)
Expand All @@ -25,5 +26,5 @@ ffprobe :: String -> IO (Either String FFProbeData)
ffprobe path = do
probeRes <- execFFProbe path
return $ case probeRes of
Right rawJson -> eitherDecodeStrict (pack rawJson)
Right rawJson -> eitherDecodeStrict (encodeUtf8 $ pack rawJson)
Left err -> Left err
7 changes: 7 additions & 0 deletions test/FFProbe/TestFFProbe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ specs = describe "Running ffprobe" $ do
title (chapters ffprobeData !! 1) `shouldBe` Just "Middle"
title (chapters ffprobeData !! 2) `shouldBe` Just "End"
)
it "Should Succeed at parsing unicode characters" $ do
res <- ffprobe "test/assets/test-unicode.mp4"
shouldBeRight
res
( \ffprobeData -> do
title (head (chapters ffprobeData)) `shouldBe` Just "Début"
)
Binary file added test/assets/test-unicode.mp4
Binary file not shown.

0 comments on commit 7019816

Please sign in to comment.