Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eh image parser #603

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions violet/lib/component/eh/eh_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getImagesUrl(String html) {
var doc = parse(html).querySelector("div[id='gdt']");
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions violet/lib/network/wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions violet/lib/pages/article_info/article_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions violet/test/component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
});
}
26 changes: 0 additions & 26 deletions violet/test/parse_test.dart

This file was deleted.

Loading