From a855d561fa0c4b87d3ee51b52a707adc6e04c1d2 Mon Sep 17 00:00:00 2001 From: "Emmanuel C. Jemeni" Date: Wed, 17 Apr 2024 13:35:33 +0100 Subject: [PATCH] feat: Added Imgur support --- CHANGELOG.md | 6 ++++++ FicImage/image.py | 10 ++++++++-- FicImage/main.py | 2 +- pyproject.toml | 2 +- setup.py | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcf3133..86aa321 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [//]: # (- **Fixed** for any bug fixes.) [//]: # (- **Security** in case of vulnerabilities.) +## [4.1.0] - 2024-04-17 + +### Added +- Added a user agent string to help download imgur images. + ## [4.0.0] - 2024-02-28 ### Fixed @@ -87,6 +92,7 @@ match the new README format. The content type was updated from `text/markdown` t - Released FicImageScript +[4.1.0]: https://github.com/Jemeni11/FicImage/compare/v4.0.0...v4.1.0 [4.0.0]: https://github.com/Jemeni11/FicImage/compare/v3.0.0...v4.0.0 [3.0.0]: https://github.com/Jemeni11/FicImage/compare/v2.1.0...v3.0.0 [2.1.0]: https://github.com/Jemeni11/FicImage/compare/v2.0.0...v2.1.0 diff --git a/FicImage/image.py b/FicImage/image.py index 4475fcf..ab948d9 100644 --- a/FicImage/image.py +++ b/FicImage/image.py @@ -49,9 +49,15 @@ def get_image_from_url( imgdata = PIL_Image_to_bytes(compressed_base64_image, file_ext) return imgdata, file_ext, f"image/{file_ext}" - + elif url.startswith("https://imgur.com/"): + url = "https://i.imgur.com/" + url.split("https://imgur.com/")[-1] + with requests.Session() as session: - img = session.get(url, stream=True) + headers = { + 'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/122.0.0.0 Safari/537.36" + } + img = session.get(url, stream=True, headers=headers) if img.headers.get("content-type", "") == "image/svg+xml": return img.content, "svg", "image/svg+xml" diff --git a/FicImage/main.py b/FicImage/main.py index a96d117..304add1 100644 --- a/FicImage/main.py +++ b/FicImage/main.py @@ -7,7 +7,7 @@ from .image import get_image_from_url from .utils import config_check, load_config_json, default_ficimage_settings -__version__ = "4.0.0" +__version__ = "4.1.0" def update_epub(path_to_epub, config_file_path, debug): diff --git a/pyproject.toml b/pyproject.toml index a023e3c..9b20052 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "FicImageScript" -version = "4.0.0" +version = "4.1.0" authors = [ { name="Emmanuel C. Jemeni", email="jemenichinonso11@gmail.com" } ] diff --git a/setup.py b/setup.py index 19fce32..9b19802 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="FicImageScript", - version="4.0.0", + version="4.1.0", author="Emmanuel C. Jemeni", author_email="jemenichinonso11@gmail.com", description="FicImage is an application designed to enhance the reading experience of FicHub epubs.",