Skip to content

Commit

Permalink
Add getEHashById
Browse files Browse the repository at this point in the history
  • Loading branch information
TaYaKi71751 committed Dec 26, 2023
1 parent b10f0fb commit c774f95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
18 changes: 18 additions & 0 deletions lib/component/eh/eh_headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (C) 2020-2023. violet-team. Licensed under the Apache-2.0 License.

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/network/wrapper.dart' as http;
Expand Down Expand Up @@ -116,4 +117,21 @@ class EHSession {
body: 'commenttext_new=${Uri.encodeFull(content)}'))
.body;
}
static Future<String> getEHashById(String id) async {
if(id.isEmpty) throw Error();
var ehash;
await Future.forEach(['e-hentai.org','exhentai.org'],(host) async {
if(ehash != null) return;
try {
final list_html = await EHSession.requestString('https://${host}/?next=${(int.parse(id) + 1)}');
final doc = parse(list_html);
final _ehash = doc.querySelector('a[href*="/g/${id}"]')?.attributes['href']?.split('/').lastWhere((element) => element.isNotEmpty);
if(_ehash == null) return;
if(ehash == null) ehash = _ehash;
} catch(e,st){
return;
}
});
return ehash ?? '';
}
}
12 changes: 1 addition & 11 deletions lib/component/hentai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,7 @@ class HentaiManager {
'$st');
try {
late var gallery_url,gallery_token;
var list_html = await EHSession.requestString(
'https://e-hentai.org/?next=${(no + 1)}'
);
parse(list_html)
.querySelector('a[href*="/g/$no/"]')
?.attributes.forEach((key, value) {
if(key == 'href'){
gallery_url = value;
gallery_token = value.split('/').lastWhere((element) => element.isNotEmpty);
}
});
gallery_token = await EHSession.getEHashById('${no}');
var html = await EHSession.requestString('https://e-hentai.org/g/${no}/${gallery_token}/?p=0&inline_set=ts_m');
var article_eh = EHParser.parseArticleData(html);
var meta = {
Expand Down
12 changes: 2 additions & 10 deletions lib/pages/bookmark/group/group_article_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ class _GroupArticleListPageState extends State<GroupArticleListPage> {
}

Future<QueryResult> _tryGetArticleFromEhentai(String id) async {
final listHtml = await EHSession.requestString(
'https://e-hentai.org/?next=${(int.parse(id) + 1)}');
final href =
parse(listHtml).querySelector('a[href*="/g/$id/"]')?.attributes['href'];
final hash = href!.split('/').lastWhere((element) => element.isNotEmpty);
final hash = await EHSession.getEHashById(id);
final html = await EHSession.requestString(
'https://e-hentai.org/g/$id/$hash/?p=0&inline_set=ts_m');
final articleEh = EHParser.parseArticleData(html);
Expand All @@ -124,11 +120,7 @@ class _GroupArticleListPageState extends State<GroupArticleListPage> {
}

Future<QueryResult> _tryGetArticleFromExhentai(String id) async {
final listHtml = await EHSession.requestString(
'https://exhentai.org/?next=${(int.parse(id) + 1)}');
final href =
parse(listHtml).querySelector('a[href*="/g/$id/"]')?.attributes['href'];
final hash = href!.split('/').lastWhere((element) => element.isNotEmpty);
final hash = EHSession.getEHashById(id);
final html = await EHSession.requestString(
'https://exhentai.org/g/$id/$hash/?p=0&inline_set=ts_m');
final articleEh = EHParser.parseArticleData(html);
Expand Down

0 comments on commit c774f95

Please sign in to comment.