From 12bf0077c222c21d9fa3136f9188f1ad1bc9e333 Mon Sep 17 00:00:00 2001 From: Indekkusu545 <30483813+Indekkusu545@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:45:07 +0800 Subject: [PATCH] fix: gallery images on both e-hentai and exhentai --- lib/common/parser/gallery_detail_parser.dart | 58 +++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/lib/common/parser/gallery_detail_parser.dart b/lib/common/parser/gallery_detail_parser.dart index bd3371784..cbf8bfc11 100644 --- a/lib/common/parser/gallery_detail_parser.dart +++ b/lib/common/parser/gallery_detail_parser.dart @@ -373,16 +373,13 @@ List parseGalleryImageFromHtml(String response) { /// 缩略图处理 List parseGalleryImage(Document document) { - // 大图 #gdt > div.gdtl 小图 #gdt > a - // TODO(Indekkusu545): 暂不清楚现在大图小图是否统一. - final List picLsit = document.querySelectorAll('#gdt > a'); - final List galleryImages = []; + // 小图 #gdt > div.gdtm + List 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) ?? ''; @@ -392,9 +389,9 @@ List 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), @@ -406,9 +403,12 @@ List parseGalleryImage(Document document) { offSet: double.parse(offSet), )); } - } else { - final List 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'); @@ -429,8 +429,40 @@ List 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; }