From 086bd1d5c7835f4c333ec1ad82bf8c89cb81a927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=85=B1=E5=A4=A9=E5=B0=8F=E7=A6=BD=E5=85=BD?= <jiangtian616@qq.com> Date: Fri, 27 Oct 2023 23:05:40 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20the=20problem=20with=20reading=20or=20dow?= =?UTF-8?q?nload=20original=20image=20=E8=A1=A5=E5=85=85=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=8E=9F=E5=9B=BE=E4=BF=9D=E5=AD=98&=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/v7.4.5+144.md | 5 +++++ lib/src/utils/eh_spider_parser.dart | 30 +++++++++++++++++------------ pubspec.yaml | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 changelog/v7.4.5+144.md diff --git a/changelog/v7.4.5+144.md b/changelog/v7.4.5+144.md new file mode 100644 index 00000000..a8f2c6fe --- /dev/null +++ b/changelog/v7.4.5+144.md @@ -0,0 +1,5 @@ +1. 补充适配原图保存&下载逻辑 + +------------------------------------------------------------------------------------------ + +1. Fix the problem with reading or download original image \ No newline at end of file diff --git a/lib/src/utils/eh_spider_parser.dart b/lib/src/utils/eh_spider_parser.dart index c18c7e3d..de301dac 100644 --- a/lib/src/utils/eh_spider_parser.dart +++ b/lib/src/utils/eh_spider_parser.dart @@ -428,17 +428,20 @@ class EHSpiderParser { if (img == null && document.querySelector('#pane_images') != null) { throw EHException(type: EHExceptionType.unsupportedImagePageStyle, message: 'unsupportedImagePageStyle'.tr); } - Element a = document.querySelector('#i6 a')!; /// height: 1600px; width: 1124px; String style = img!.attributes['style']!; String url = img.attributes['src']!; - if (url.contains('509.gif')) { throw EHException(type: EHExceptionType.exceedLimit, message: 'exceedImageLimits'.tr); } + double height = double.parse(RegExp(r'height:(\d+)px').firstMatch(style)!.group(1)!); + double width = double.parse(RegExp(r'width:(\d+)px').firstMatch(style)!.group(1)!); + + Element hashElement = document.querySelector('#i6 div a')!; + String imageHash = RegExp(r'f_shash=(\w+)').firstMatch(hashElement.attributes['href']!)!.group(1)!; - Element? originalImg = document.querySelector('#i7 > a'); + Element? originalImg = document.querySelector('#i6:nth-child(3) a'); String? originalImgHref = originalImg?.attributes['href']; RegExpMatch? originalImgWidthAndHeight = RegExp(r'(\d+) x (\d+)').firstMatch(originalImg?.text ?? ''); double? originalImgWidth = double.tryParse(originalImgWidthAndHeight?.group(1) ?? ''); @@ -446,12 +449,12 @@ class EHSpiderParser { return GalleryImage( url: url, - height: double.parse(RegExp(r'height:(\d+)px').firstMatch(style)!.group(1)!), - width: double.parse(RegExp(r'width:(\d+)px').firstMatch(style)!.group(1)!), + height: height, + width: width, originalImageUrl: originalImgHref, originalImageWidth: originalImgWidth, originalImageHeight: originalImgHeight, - imageHash: RegExp(r'f_shash=(\w+)').firstMatch(a.attributes['href']!)!.group(1)!, + imageHash: imageHash, ); } @@ -461,17 +464,20 @@ class EHSpiderParser { if (img == null && document.querySelector('#pane_images') != null) { throw EHException(type: EHExceptionType.unsupportedImagePageStyle, message: 'unsupportedImagePageStyle'.tr); } - Element a = document.querySelector('#i6 > a')!; /// height: 1600px; width: 1124px; String style = img!.attributes['style']!; String url = img.attributes['src']!; - if (url.contains('509.gif')) { throw EHException(type: EHExceptionType.exceedLimit, message: 'exceedImageLimits'.tr); } + double height = double.parse(RegExp(r'height:(\d+)px').firstMatch(style)!.group(1)!); + double width = double.parse(RegExp(r'width:(\d+)px').firstMatch(style)!.group(1)!); + + Element hashElement = document.querySelector('#i6 div a')!; + String imageHash = RegExp(r'f_shash=(\w+)').firstMatch(hashElement.attributes['href']!)!.group(1)!; - Element? originalImg = document.querySelector('#i7 > a'); + Element? originalImg = document.querySelector('#i6:nth-child(3) a'); String? originalImgHref = originalImg?.attributes['href']; RegExpMatch? originalImgWidthAndHeight = RegExp(r'(\d+) x (\d+)').firstMatch(originalImg?.text ?? ''); double? originalImgWidth = double.tryParse(originalImgWidthAndHeight?.group(1) ?? ''); @@ -479,9 +485,9 @@ class EHSpiderParser { return GalleryImage( url: originalImgHref ?? url, - height: originalImgHeight ?? double.parse(RegExp(r'height:(\d+)px').firstMatch(style)!.group(1)!), - width: originalImgWidth ?? double.parse(RegExp(r'width:(\d+)px').firstMatch(style)!.group(1)!), - imageHash: RegExp(r'f_shash=(\w+)').firstMatch(a.attributes['href']!)!.group(1)!, + height: originalImgHeight ?? height, + width: originalImgWidth ?? width, + imageHash: imageHash, ); } diff --git a/pubspec.yaml b/pubspec.yaml index 5cea15fb..80aed33e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: jhentai description: A flutter app for E-Hentai/EXHentai publish_to: 'none' -version: 7.4.4+143 +version: 7.4.5+144 environment: sdk: '>=3.0.0 <4.0.0'