Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add thumbnail extraction for ePub files #387

Closed
wants to merge 92 commits into from

Conversation

JorgeRui
Copy link
Contributor

@JorgeRui JorgeRui commented Aug 24, 2024

Implemented _epub_cover method to extract and render the cover image from ePub files. The method scans the contents of the ePub (treated as a ZIP archive) and searches for image files (e.g., .png, .jpg, .jpeg, .gif, .bmp, .svg). This feature enables the generation of thumbnails for ePub files, enhancing the application's ability to display visual representations of eBooks.

Closes partially #360

Other ebooks file formats are yet not supported, as each one of them have their one unique specifications. This method can be reused for ibooks in theory, but haven't tested it.

image
image

Creepler13 and others added 30 commits June 13, 2024 10:59
* Ability to drop local files in to TagStudio to add to library

* Added renaming option to drop import

* Improved readability and switched to pathLib

* format

* Apply suggestions from code review

Co-authored-by: yed podtrzitko <[email protected]>

* Revert Change

* Update tagstudio/src/qt/modals/drop_import.py

Co-authored-by: yed podtrzitko <[email protected]>

* Added support for folders

* formatting

* Progress bars added

* Added Ability to Drag out of window

* f

* format

* Ability to drop local files in to TagStudio to add to library

* Added renaming option to drop import

* Improved readability and switched to pathLib

* format

* Apply suggestions from code review

Co-authored-by: yed podtrzitko <[email protected]>

* Revert Change

* Update tagstudio/src/qt/modals/drop_import.py

Co-authored-by: yed podtrzitko <[email protected]>

* Added support for folders

* formatting

* Progress bars added

* Added Ability to Drag out of window

* f

* format

* format

* formatting and refactor

* format again

* formatting for mypy

* convert lambda to func for clarity

* mypy fixes

* fixed dragout only worked on selected

* Refactor typo, Add license

* Reformat QMessageBox

* Disable drops when no library is open

---------

Co-authored-by: yed podtrzitko <[email protected]>
Co-authored-by: Travis Abendshien <[email protected]>
…oDev#289)

* fix: python complaining about backslashes inside f-string expressions
refactor excessively long f-string into separate variables

* fix: missing f on f-string

* Format with Ruff
* Update thumb_renderer.py

Included support for rendering blender thumbnails

* Add files via upload

Add functions that get the thumbnail's data

* Update thumb_renderer.py

* Update blender_thumbnailer.py

* Update thumb_renderer.py

* Update thumb_renderer.py

Changed where imports are according to feedback

* Update thumb_renderer.py

Changed blender thumbnail function name to reduce ambiguity

* Update blender_thumbnailer.py

Updated function name

* Update blender_thumbnailer.py

* Update blender_thumbnailer.py

Ruff format

* Update thumb_renderer.py

Ruff format

* Update constants.py

Add .blend1, 2, 3 etc file support

* Update blender_thumbnailer.py

Refactor to follow requested changes

* Update thumb_renderer.py

More refactoring

* Update blender_thumbnailer.py

Ruff format

* Update thumb_renderer.py

Ruff format
* use list widget for selecting fields to add

* fix(ui): allow list widget resizing
* Fixed merge conflicts

* fixed format?

* Improve readability (Apply suggestions from code review)

Co-authored-by: yed podtrzitko <[email protected]>

* bug fix: Copy last selected not first

* Fix copy entanglement; Fix paste overwriting

* Change multi-selection copy to merge data

- Multi-selection copy now merges fields of all selected entries
- Action states are now handled

---------

Co-authored-by: yed podtrzitko <[email protected]>
Co-authored-by: Travis Abendshien <[email protected]>
* Add font thumbnail preview support

* Add multiple font sizes to thumbnail

* Ruff reformat

* Ruff reformat

* Added Metadata to info

* Change the way thumbnails are structured

* Small performance improvement

* changed Metadata display structure

* added copyright notice to added file

* fix(ui): dynamically scale font previews; add .woff2, .ttc

---------

Co-authored-by: Travis Abendshien <[email protected]>
- Fix RAW images not being loaded correctly in the preview panel
- Fix trying to read size data from null images
- Refactor `os.stat` to `<Path object>.stat()`
- Remove unnecessary upper/lower conversions
- Improve encoding compatibility beyond UTF-8 when reading text files
- Code cleanup
CyanVoxel and others added 12 commits August 31, 2024 22:40
…StudioDev#430)

* feat(ui): show file dates, change path look

* use `os.path.sep`

* refactor: simplify file label cases
)

* fix: Do not create command prompt window on subcmd

Patches files from abandoned libraries are located and updated in
src/qt/helpers/vendored with modified sections labeld PATCHED. A wrapper
around subprocess.Popen automatically sets the creation flag to no
window on windows.

* fix: Replace Popen in mediainfo_json decoder

* fixup: Pipe stdin to stdin

* chore: Exclude vendored dir from tooling checks

* suppress mypy warnings
…#472)

* fix(PreviewPanel): Use birthtime for creation time

st_ctime does not provide accurate creation time on MacOS, and as of
Python 3.12 is deprecated for Windows. On these two platforms use
st_birthtime, but fall back to st_ctime on linux.

* mypy errors
* fix(ThumbRenderer): Use audio icon when no ffmpeg

When ffmpeg is missing, Popen raises a FileNotFound error. This would
be caught as an Unlinked file and use the broken file icon. The
exception is now caught and a more appropriate exception is raised in
its place.

* ruff formatting
@Leseratte10
Copy link

Is it a good idea to just pick the first image that's present in the EPUB file? That's not necessarily the cover, it may also be another random image from the book.

A better way would be to parse the XML at /META-INF/container.xml (standardized path), follow the path to the OPF file that's mentioned there, and then find any cover files defined in there, like this python script.

CyanVoxel and others added 6 commits September 9, 2024 12:09
The cutoff for how many files get sorted also changes to 150,000.
* fix(QtDriver): Retain filter on directory refresh

* ruff formatting
* feat: increase file scanning performance

* fix: correct typo in comment

* refactor: use `continue` in place of nested `ifs`
* feat: Warn user if FFmpeg is not installed

Creates a Warning dialog on startup if the program cannot find FFmpeg or
FFprobe in the PATH. Other interactions with the program are blocked
until the issue is either ignore or resolved.

* docs: Add FFmpeg installation guide

* ruff formatting

* chore: Cleanup missing logic and warning message

* chore: Remove custom icon

Per QT docs, handling custom iconPixmap requires multiple icons per
platform. Easier to just use universal, default warning icon (yellow
triangle)

* fix: Ignore dialog with X button

* fix: Move startup checks after CI

* chore: Unreverse install check logic

* doc: Improve docs formatting

* docs: Point help url to new docs sites

* Remove ffmpeg docs page

* Use which from python stdlib
@@ -764,6 +766,33 @@ def _video_thumb(self, filepath: Path) -> Image.Image:
)
return im

def _epub_cover(self, filepath: Path) -> Image.Image:
Copy link
Collaborator

@yedpodtrzitko yedpodtrzitko Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be a nice to have test for similar this:

from syrupy.extensions.image import PNGImageSnapshotExtension


def test_epub_to_png(snapshot):
    file_path = Path(__file__).parent / "fixtures" / "sample.epub"

    png_image = ThumbRenderer(...)._epub_cover(file_path, 600)
    assert png_image.read() == snapshot(extension_class=PNGImageSnapshotExtension)

@CyanVoxel CyanVoxel changed the base branch from thumbnails to Alpha-v9.4 September 15, 2024 08:19
@CyanVoxel
Copy link
Member

I'm moved this PR from the deprecated thumbnails branch to Alpha-v9.4, which is the branch that thumbnails was eventually merged into. However the v9.4.x releases are now feature frozen and are now solely reserved for bugfixes. This means that after the changes from thumbnails are ported to main that I'll once again be moving the target for this PR over to there as a v9.5 feature.

Sorry for the disruption, and thank you for your patience.

@CyanVoxel CyanVoxel added the Status: Review Needed A review of this is needed label Oct 7, 2024
@CyanVoxel CyanVoxel changed the base branch from Alpha-v9.4 to main October 7, 2024 22:17
@CyanVoxel
Copy link
Member

Closed in favor of #539 which ports the commits here over to a clean branch.

@CyanVoxel CyanVoxel closed this Oct 10, 2024
@CyanVoxel CyanVoxel removed the Status: Review Needed A review of this is needed label Oct 10, 2024
CyanVoxel added a commit that referenced this pull request Oct 17, 2024
* feat: add ePub thumbnail support

Co-Authored-By: Jorge Rui Da Silva Barrios <[email protected]>

* tests: compare epub cover against png snapshot

Co-Authored-By: yed <[email protected]>

* test: optimize epub test file

---------

Co-authored-by: Jorge Rui Da Silva Barrios <[email protected]>
Co-authored-by: yed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request Type: UI/UX User interface and/or user experience
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.