Skip to content

Commit

Permalink
fix: new structure of gallery images
Browse files Browse the repository at this point in the history
fix: gallery images on both e-hentai and exhentai
  • Loading branch information
Indekkusu545 authored and 3003h committed Oct 29, 2024
1 parent 6d94baa commit 95dd10b
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions lib/common/parser/gallery_detail_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,11 @@ List<GalleryImage> parseGalleryImageFromHtml(String response) {

/// 缩略图处理
List<GalleryImage> parseGalleryImage(Document document) {
// 大图 #gdt > div.gdtl 小图 #gdt > div.gdtm
final List<Element> picLsit = document.querySelectorAll('#gdt > div.gdtm');

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.querySelector('a')?.attributes['href'] ?? '';
final String style = pic.querySelector('div')?.attributes['style'] ?? '';
Expand All @@ -405,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 @@ -428,7 +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.e('No gallery images found');
return galleryImages;
}

0 comments on commit 95dd10b

Please sign in to comment.