Skip to content

Commit

Permalink
Fix the problem with reading or download original image
Browse files Browse the repository at this point in the history
补充适配原图保存&下载逻辑
  • Loading branch information
jiangtian616 committed Oct 27, 2023
1 parent d202f20 commit 086bd1d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions changelog/v7.4.5+144.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. 补充适配原图保存&下载逻辑

------------------------------------------------------------------------------------------

1. Fix the problem with reading or download original image
30 changes: 18 additions & 12 deletions lib/src/utils/eh_spider_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,30 +428,33 @@ 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) ?? '');
double? originalImgHeight = double.tryParse(originalImgWidthAndHeight?.group(2) ?? '');

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,
);
}

Expand All @@ -461,27 +464,30 @@ 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) ?? '');
double? originalImgHeight = double.tryParse(originalImgWidthAndHeight?.group(2) ?? '');

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,
);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 086bd1d

Please sign in to comment.