Skip to content

Commit

Permalink
Add duckduckgo for ehash
Browse files Browse the repository at this point in the history
  • Loading branch information
TaYaKi71751 committed Dec 26, 2023
1 parent 04b9470 commit f1379bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
25 changes: 23 additions & 2 deletions lib/component/eh/eh_headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:html/parser.dart';
import 'package:http/http.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:violet/log/log.dart';
import 'package:violet/network/wrapper.dart' as http;

class EHSession {
Expand Down Expand Up @@ -119,7 +120,7 @@ class EHSession {
}
static Future<String> getEHashById(String id) async {
if(id.isEmpty) throw Error();
var ehash;
String? ehash;
await Future.forEach(['e-hentai.org','exhentai.org'],(host) async {
if(ehash != null) return;
try {
Expand All @@ -132,6 +133,26 @@ class EHSession {
return;
}
});
return ehash ?? '';
if(ehash != null) return ehash ?? '';
if(ehash == null){
final search_res = await http.post(
"https://lite.duckduckgo.com/lite/",
body: 'q=${('https://e-hentai.org/g/${id}/').replaceAll(':', '%3A').replaceAll('/', '%2F')}&kl=&df=',
headers: {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0',
'Content-Type': 'application/x-www-form-urlencoded',
}
);
final search_html = search_res.body;
final found_url = parse(search_html)
.querySelector('[href*="/g/${id}/"]')
?.attributes['href'];
ehash = found_url?.split('/').lastWhere((element) => element.isNotEmpty);
}
if(ehash != null){
return ehash ?? '';
}
Logger.warning('[getEHashById] Could not found hash of ${id}');
throw Error();
}
}
19 changes: 13 additions & 6 deletions lib/component/hentai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,43 @@ class HentaiManager {
final v4 = ScriptManager.enableV4;

for (int i = 0; i < route.length; i++) {
var ehash;
try {
switch (route[i]) {
case 'EHentai':
if (qr.ehash() != null) {
if (qr.ehash() == null) {
ehash = await EHSession.getEHashById('${qr.id()}');
}
if (qr.ehash() != null || ehash != null) {
var html = await EHSession.requestString(
'https://e-hentai.org/g/${qr.id()}/${qr.ehash()}/?p=0&inline_set=ts_m');
'https://e-hentai.org/g/${qr.id()}/${(qr.ehash() ?? ehash)}/?p=0&inline_set=ts_m');
var article = EHParser.parseArticleData(html);
return EHentaiImageProvider(
count: article.length,
thumbnail: article.thumbnail,
pagesUrl: List<String>.generate(
(article.length / 40).ceil(),
(index) =>
'https://e-hentai.org/g/${qr.id()}/${qr.ehash()}/?p=$index'),
'https://e-hentai.org/g/${qr.id()}/${(qr.ehash() ?? ehash)}/?p=$index'),
isEHentai: true,
);
}
break;
case 'ExHentai':
if (qr.ehash() != null) {
if (qr.ehash() == null) {
ehash = await EHSession.getEHashById('${qr.id()}');
}
if (qr.ehash() != null || ehash != null) {
var html = await EHSession.requestString(
'https://exhentai.org/g/${qr.id()}/${qr.ehash()}/?p=0&inline_set=ts_m');
'https://exhentai.org/g/${qr.id()}/${(qr.ehash() ?? ehash)}/?p=0&inline_set=ts_m');
var article = EHParser.parseArticleData(html);
return EHentaiImageProvider(
count: article.length,
thumbnail: article.thumbnail,
pagesUrl: List<String>.generate(
(article.length / 40).ceil(),
(index) =>
'https://exhentai.org/g/${qr.id()}/${qr.ehash()}/?p=$index'),
'https://exhentai.org/g/${qr.id()}/${(qr.ehash() ?? ehash)}/?p=$index'),
isEHentai: false,
);
}
Expand Down

0 comments on commit f1379bb

Please sign in to comment.