Skip to content

Commit

Permalink
fix: gallery images on both e-hentai and exhentai
Browse files Browse the repository at this point in the history
  • Loading branch information
Indekkusu545 authored and honjow committed Oct 27, 2024
1 parent 12b8d79 commit 12bf007
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions lib/common/parser/gallery_detail_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,13 @@ List<GalleryImage> parseGalleryImageFromHtml(String response) {

/// 缩略图处理
List<GalleryImage> parseGalleryImage(Document document) {
// 大图 #gdt > div.gdtl 小图 #gdt > a
// TODO(Indekkusu545): 暂不清楚现在大图小图是否统一.
final List<Element> picLsit = document.querySelectorAll('#gdt > a');

final List<GalleryImage> galleryImages = [];

// 小图 #gdt > div.gdtm
List<Element> picLsit = document.querySelectorAll('#gdt > div.gdtm');
if (picLsit.isNotEmpty) {
// 小图的处理
for (final Element pic in picLsit) {
final String picHref = pic.attributes['href'] ?? '';
final String picHref = pic.querySelector('a')?.attributes['href'] ?? '';
final String style = pic.querySelector('div')?.attributes['style'] ?? '';
final String picSrcUrl =
RegExp(r'url\((.+)\)').firstMatch(style)?.group(1) ?? '';
Expand All @@ -392,9 +389,9 @@ List<GalleryImage> parseGalleryImage(Document document) {
RegExp(r'width:(\d+)?px').firstMatch(style)?.group(1) ?? '';
final String offSet =
RegExp(r'\) -(\d+)?px ').firstMatch(style)?.group(1) ?? '';
final String title = pic.querySelector('div')?.attributes['title'] ?? '';
final String picSer =
RegExp(r'Page (\d+):').firstMatch(title)?.group(1) ?? '';

final Element? imgElem = pic.querySelector('img');
final String picSer = imgElem?.attributes['alt']?.trim() ?? '';

galleryImages.add(GalleryImage(
ser: int.parse(picSer),
Expand All @@ -406,9 +403,12 @@ List<GalleryImage> parseGalleryImage(Document document) {
offSet: double.parse(offSet),
));
}
} else {
final List<Element> picLsit = document.querySelectorAll('#gdt > div.gdtl');
// 大图的处理
return galleryImages;
}

// 大图 #gdt > div.gdtl
picLsit = document.querySelectorAll('#gdt > div.gdtl');
if (picLsit.isNotEmpty) {
for (final Element pic in picLsit) {
final String picHref = pic.querySelector('a')?.attributes['href'] ?? '';
final Element? imgElem = pic.querySelector('img');
Expand All @@ -429,8 +429,40 @@ List<GalleryImage> parseGalleryImage(Document document) {
oriHeight: double.parse(height),
));
}
return galleryImages;
}

// 里站 #gdt > a
picLsit = document.querySelectorAll('#gdt > a');
if (picLsit.isNotEmpty) {
for (final Element pic in picLsit) {
final String picHref = pic.attributes['href'] ?? '';
final String style = pic.querySelector('div')?.attributes['style'] ?? '';
final String picSrcUrl =
RegExp(r'url\((.+)\)').firstMatch(style)?.group(1) ?? '';
final String height =
RegExp(r'height:(\d+)?px').firstMatch(style)?.group(1) ?? '';
final String width =
RegExp(r'width:(\d+)?px').firstMatch(style)?.group(1) ?? '';
final String offSet =
RegExp(r'\) -(\d+)?px ').firstMatch(style)?.group(1) ?? '';
final String title = pic.querySelector('div')?.attributes['title'] ?? '';
final String picSer =
RegExp(r'Page (\d+):').firstMatch(title)?.group(1) ?? '';

galleryImages.add(GalleryImage(
ser: int.parse(picSer),
largeThumb: false,
href: picHref,
thumbUrl: picSrcUrl,
thumbHeight: double.parse(height),
thumbWidth: double.parse(width),
offSet: double.parse(offSet),
));
}
return galleryImages;
}

logger.d('galleryImages.length: ${galleryImages.length}');
logger.e('No gallery images found');
return galleryImages;
}

0 comments on commit 12bf007

Please sign in to comment.