diff --git a/violet/lib/component/eh/eh_parser.dart b/violet/lib/component/eh/eh_parser.dart index 2a1079453..87521da91 100644 --- a/violet/lib/component/eh/eh_parser.dart +++ b/violet/lib/component/eh/eh_parser.dart @@ -58,6 +58,12 @@ class EHParser { static final RegExp _thumbnailPattern = RegExp(r'https://(s\.)?(exhentai|ehgt).org/.*?(?=\))'); + static bool validHtml(String html) { + final removed = + html.contains('This gallery has been removed or is unavailable.'); + return !removed; + } + // ex: https://exhentai.org/g/1212168/421ef300a8/ static List getImagesUrl(String html) { var doc = parse(html).querySelector("div[id='gdt']"); @@ -68,6 +74,10 @@ class EHParser { var url = element.querySelector('a')!.attributes['href']; if (!result.contains(url)) result.add(url!); }); + doc.querySelectorAll('a').forEach((element) { + var url = element.attributes['href']; + if (!result.contains(url)) result.add(url!); + }); return result; } diff --git a/violet/lib/network/wrapper.dart b/violet/lib/network/wrapper.dart index bdcd1ec02..88168d6f7 100644 --- a/violet/lib/network/wrapper.dart +++ b/violet/lib/network/wrapper.dart @@ -12,9 +12,9 @@ import 'package:violet/thread/semaphore.dart'; class HttpWrapper { static String accept = - 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'; + 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'; static String userAgent = - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'; + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'; static String mobileUserAgent = 'Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Mobile Safari/537.36'; static Semaphore throttlerExHentai = Semaphore(maxCount: 1); diff --git a/violet/lib/pages/article_info/article_info_page.dart b/violet/lib/pages/article_info/article_info_page.dart index bfa51f2f8..82b5de17e 100644 --- a/violet/lib/pages/article_info/article_info_page.dart +++ b/violet/lib/pages/article_info/article_info_page.dart @@ -540,8 +540,7 @@ class __CommentAreaState extends State<_CommentArea> { final html = (await http.get( 'https://e-hentai.org/g/${widget.queryResult.id()}/${widget.queryResult.ehash()}/?p=0&inline_set=ts_l')) .body; - if (html - .contains('This gallery has been removed or is unavailable.')) { + if (!EHParser.validHtml(html)) { return; } final article = EHParser.parseArticleData(html); diff --git a/violet/test/component_test.dart b/violet/test/component_test.dart index 7759acdd5..50701ad3e 100644 --- a/violet/test/component_test.dart +++ b/violet/test/component_test.dart @@ -4,8 +4,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:violet/component/eh/eh_headers.dart'; import 'package:violet/component/eh/eh_parser.dart'; import 'package:violet/component/hentai.dart'; +import 'package:violet/database/query.dart'; import 'package:violet/settings/settings.dart'; void main() { @@ -52,4 +54,26 @@ Page 20: 020.jpg" src="https://exhentai.org/t/66/55/6655fb520e13eff74ebf9aa49c21 expect(EHParser.getThumbnailImages(body).length, 2); }); + + test('EHentai Image Provider', () async { + // https://exhentai.org/g/3175025/58a5600a77/ + Settings.routingRule = ['ExHentai', 'EHentai']; + final query = QueryResult(result: {'Id': 3175025, 'EHash': '58a5600a77'}); + final provider = await HentaiManager.getImageProvider(query); + expect(provider.length(), 25); + }); + + test('EHentai Parse Article Data', () async { + final html = await EHSession.requestString( + 'https://exhentai.org/g/2504057/6757b3c4b8/'); + final article = EHParser.parseArticleData(html); + expect(article.comment!.isNotEmpty, true); + }); + + test('EHentai Get Images Url', () async { + final html = await EHSession.requestString( + 'https://exhentai.org/g/3176408/87646440e1/?p=0&inline_set=ts_m'); + final urls = EHParser.getImagesUrl(html); + expect(urls.length, 20); + }); } diff --git a/violet/test/parse_test.dart b/violet/test/parse_test.dart deleted file mode 100644 index a8294232a..000000000 --- a/violet/test/parse_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -// This source code is a part of Project Violet. -// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:http/http.dart' as http; -import 'package:violet/component/eh/eh_parser.dart'; - -void main() { - setUp(() async { - WidgetsFlutterBinding.ensureInitialized(); - }); - - test('Test Parse ExHentai', () async { - final html = (await http.get( - Uri.parse('https://exhentai.org/g/2504057/6757b3c4b8/'), - headers: { - 'Cookie': - 'ipb_member_id=2742770; ipb_pass_hash=622fcc2be82c922135bb0516e0ee497d; sk=t8inbzaqn45ttyn9f78eanzuqizh; igneous=rcrmcztqgf1v8p1e0' - })) - .body; - - expect(EHParser.parseArticleData(html).comment!.isNotEmpty, true); - }); -}