From 80c83b921b440ea345783b8a9f26dc0acb87abd4 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 25 Oct 2022 17:16:52 +0200 Subject: compiler: fix exif-rotated image dimension retrieval GitHub: fixes #336 --- compiler/src/FileProcessors.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler/src') diff --git a/compiler/src/FileProcessors.hs b/compiler/src/FileProcessors.hs index 6e1738e..db5c9a1 100644 --- a/compiler/src/FileProcessors.hs +++ b/compiler/src/FileProcessors.hs @@ -100,7 +100,8 @@ type FileDescriber a = getImageResolution :: FilePath -> IO Resolution getImageResolution fsPath = - readProcess "magick" ["identify", "-format", "%w %h", firstFrame] [] + readProcess "magick" + ["identify", "-auto-orient", "-format", "%w %h", firstFrame] [] >>= parseResolution . break (== ' ') where firstFrame :: FilePath -- cgit v1.2.3 From f23c5e5b2cc837093e029884eae1f2edeaa4c888 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:31:47 +0200 Subject: compiler: add log messages for early steps This adds some messages signaling that the compiler is doing something when it is enumerating the input tree and reading metadata files, which may take a while on systems with slow IO such as when using a network share. GitHub: closes #344 --- compiler/src/Compiler.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler/src') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 4111f02..d92d8e9 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -85,7 +85,8 @@ loadGalleryIndex path = doesFileExist path >>= bool (return Nothing) decodeIndex where decodeIndex = - JSON.eitherDecodeFileStrict path + putStrLn ("Loading previous index:\t" ++ path) + >> JSON.eitherDecodeFileStrict path >>= either (\err -> warn err >> return Nothing) (return . Just) warn = putStrLn . ("Warning:\tUnable to reuse existing index as cache: " ++) @@ -136,10 +137,13 @@ compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDir do config <- readConfig $ inputGalleryConf configPath + putStrLn "Inventorying input files" inputDir <- readDirectory inputDirPath excludedCanonicalDirs <- mapM canonicalizePath excludedDirs + let sourceFilter = galleryDirFilter config excludedCanonicalDirs let sourceTree = filterDir sourceFilter inputDir + putStrLn "Reading input metadata" inputTree <- readInputTree sourceTree let curatedInputTree = filterInputTree (inputTreeFilter config) inputTree -- cgit v1.2.3 From 736520e5e17eee490565c98cd037363fd3e34aed Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 31 Oct 2022 00:14:07 +0100 Subject: compiler,viewer: register EPUB item type --- compiler/src/ItemProcessors.hs | 5 ++++- compiler/src/Resource.hs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler/src') diff --git a/compiler/src/ItemProcessors.hs b/compiler/src/ItemProcessors.hs index fa99316..6035477 100644 --- a/compiler/src/ItemProcessors.hs +++ b/compiler/src/ItemProcessors.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -38,6 +38,7 @@ data Format = | PlainTextFormat | MarkdownFormat | PortableDocumentFormat + | EPUBFormat | VideoFormat | AudioFormat | Unknown @@ -59,6 +60,7 @@ formatFromPath = ".txt" -> PlainTextFormat ".md" -> MarkdownFormat ".pdf" -> PortableDocumentFormat + ".epub" -> EPUBFormat ".wav" -> AudioFormat ".oga" -> AudioFormat ".ogg" -> AudioFormat @@ -103,6 +105,7 @@ itemFileProcessor maxResolution = processorFor PlainTextFormat _ = copyResource PlainText processorFor MarkdownFormat _ = copyResource Markdown processorFor PortableDocumentFormat _ = copyResource PDF + processorFor EPUBFormat _ = copyResource EPUB processorFor VideoFormat _ = copyResource Video processorFor AudioFormat _ = copyResource Audio processorFor Unknown _ = copyResource Other diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 804c9a1..1868512 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -92,6 +92,7 @@ data GalleryItemProps = | PlainText { resource :: Resource } | Markdown { resource :: Resource } | PDF { resource :: Resource } + | EPUB { resource :: Resource } | Video { resource :: Resource } | Audio { resource :: Resource } | Other { resource :: Resource } -- cgit v1.2.3 From 922481cfd39543128396dca05c7a83588bcd332e Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 1 Dec 2022 20:00:12 +0100 Subject: compiler: fix build for ghc 9.2 --- compiler/src/Input.hs | 6 ++---- compiler/src/Resource.hs | 15 ++++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'compiler/src') diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index 4cfabe6..7990571 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -153,6 +153,4 @@ filterInputTree cond = filterNode filterNode :: InputTree -> InputTree filterNode inputFile@InputFile{} = inputFile filterNode inputDir@InputDir{items} = - filter cond items - & map filterNode - & \curatedItems -> inputDir { items = curatedItems } :: InputTree + inputDir { Input.items = filter cond items & map filterNode } diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 1868512..e8ca58c 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -56,7 +56,7 @@ encodingOptions :: JSON.Options encodingOptions = JSON.defaultOptions { JSON.fieldLabelModifier = map toLower , JSON.constructorTagModifier = map toLower - , JSON.sumEncoding = JSON.defaultTaggedObject + , JSON.sumEncoding = JSON.TaggedObject { JSON.tagFieldName = "type" , JSON.contentsFieldName = "contents" } @@ -180,7 +180,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig = & map (prefix tagsFromDirsConfig ++) aggregateTags :: [GalleryItem] -> [Tag] - aggregateTags = concatMap (\item -> tags (item::GalleryItem)) + aggregateTags = concatMap Resource.tags maybeThumbnail :: Path -> Maybe Path -> IO (Maybe Thumbnail) maybeThumbnail _ Nothing = return Nothing @@ -188,7 +188,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig = mostRecentModTime :: [GalleryItem] -> Maybe ZonedTime mostRecentModTime = - maximumByMay comparingTime . map (datetime::(GalleryItem -> ZonedTime)) + maximumByMay comparingTime . map Resource.datetime comparingTime :: ZonedTime -> ZonedTime -> Ordering comparingTime l r = compare (zonedTimeToUTC l) (zonedTimeToUTC r) @@ -220,14 +220,11 @@ galleryOutputDiff resources ref = resPath :: GalleryItemProps -> Maybe Path resPath Directory{} = Nothing - resPath resourceProps = - Just - $ resourcePath - $ (resource :: (GalleryItemProps -> Resource)) resourceProps + resPath resourceProps = Just $ resourcePath $ resourceProps.resource thumbnailPaths :: [GalleryItem] -> [Path] thumbnailPaths = - map (resourcePath . (resource :: (Thumbnail -> Resource))) + map (\thumbnail -> resourcePath thumbnail.resource) . mapMaybe thumbnail (\\) :: [Path] -> [Path] -> [Path] -- cgit v1.2.3 From 828f033e80773b38842cca6c30c3c08f320f6e1f Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 27 Dec 2022 22:55:30 +0100 Subject: compiler: handle dimension flip internally ImageMagick's `-auto-rotate` flag prevents the use of `-ping`, forcing the whole files to be loaded just to read the adjusted width and height. This makes the compiler handle the dimension flipping internally while using `-ping`, which should be way faster. --- compiler/src/FileProcessors.hs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'compiler/src') diff --git a/compiler/src/FileProcessors.hs b/compiler/src/FileProcessors.hs index db5c9a1..78e7351 100644 --- a/compiler/src/FileProcessors.hs +++ b/compiler/src/FileProcessors.hs @@ -101,17 +101,34 @@ type FileDescriber a = getImageResolution :: FilePath -> IO Resolution getImageResolution fsPath = readProcess "magick" - ["identify", "-auto-orient", "-format", "%w %h", firstFrame] [] - >>= parseResolution . break (== ' ') + [ "identify" + , "-ping" + , "-format", "%[orientation] %w %h" + , firstFrame + ] [] + >>= parseOutput . words + where firstFrame :: FilePath firstFrame = fsPath ++ "[0]" + -- Flip the dimensions when necessary according to the metadata. + -- ImageMagick's `-auto-orient` flag does the same, but isn't compatible + -- with `-ping` and causes the whole image file to be loaded. + parseOutput :: [String] -> IO Resolution + parseOutput ["RightTop", w, h] = parseResolution (h, w) + parseOutput ["LeftBottom", w, h] = parseResolution (h, w) + parseOutput [_, w, h] = parseResolution (w, h) + parseOutput _ = throwIO failedRead + parseResolution :: (String, String) -> IO Resolution parseResolution (widthString, heightString) = case (readMaybe widthString, readMaybe heightString) of (Just w, Just h) -> return $ Resolution w h - _ -> throwIO $ ProcessingException fsPath "Unable to read image resolution." + _ -> throwIO failedRead + + failedRead :: ProcessingException + failedRead = ProcessingException fsPath "Unable to read image resolution." resourceAt :: FileDescriber Resource resourceAt resPath fsPath = Resource resPath <$> getModificationTime fsPath -- cgit v1.2.3