Fixed 'stuck in solve captcha screen'

This commit is contained in:
dstark5
2025-03-03 19:44:53 +05:30
parent a363a883d7
commit bfad3f92f2
6 changed files with 67 additions and 63 deletions

View File

@ -162,52 +162,43 @@ class AnnasArchieve {
Future<BookInfoData?> _bookInfoParser(resData, url) async { Future<BookInfoData?> _bookInfoParser(resData, url) async {
var document = parse(resData.toString()); var document = parse(resData.toString());
var main = document.querySelector('main[class="main"]'); var main = document.querySelector('main[class="main"]');
var ul = main?.querySelectorAll('ul[class="list-inside mb-4 ml-1"]'); var ul = main?.querySelectorAll('ul[class="list-inside mb-4 ml-1"]>li>a');
var externalUrlAnchorTags = main
?.querySelector(
'ul[class="list-inside mb-4 ml-1 js-show-external hidden"]')
?.querySelectorAll('li>a');
// List<String> mirrors = []; // List<String> mirrors = [];
// if (ul != null) {
// var anchorTags = [];
// for (var e in ul) {
// anchorTags.insertAll(0, e.querySelectorAll('a'));
// }
// for (var element in anchorTags) {
// if (element.attributes['href'] != null &&
// element.attributes['href']!.startsWith('/slow_download') &&
// element.attributes['href']!.endsWith('/2')) {
// String? url =
// await _getMirrorLink('$baseUrl${element.attributes['href']!}');
// if (url != null && url.isNotEmpty) {
// mirrors.add(url);
// }
// } else if (element.attributes['href']!.startsWith('https://')) {
// if (element.attributes['href'] != null &&
// element.attributes['href'].contains('ipfs') == true) {
// mirrors.add(element.attributes['href']!);
// }
// }
// }
// }
String? mirror; String? mirror;
var anchorTags = []; var anchorTags = [];
if (ul != null) { if (ul != null) {
for (var e in ul) { for (var element in ul) {
anchorTags.insertAll(0, e.querySelectorAll('a')); if (element.attributes['href'] != null &&
element.attributes['href']!.startsWith('/slow_download') &&
element.attributes['href']!.endsWith('/2')) {
mirror = '$baseUrl${element.attributes['href']}';
}
} }
} }
for (var element in anchorTags) { if (mirror == null) {
if (element.attributes['href'] != null && if (externalUrlAnchorTags != null) {
element.attributes['href']!.startsWith('/slow_download') && for (var e in externalUrlAnchorTags) {
element.attributes['href']!.endsWith('/2')) { if (e.attributes['href'] != null) {
mirror = '$baseUrl${element.attributes['href']}'; anchorTags.add(e.attributes['href']);
}
}
}
for (var element in anchorTags) {
if (element.startsWith('/ipfs_downloads')) {
mirror = '$baseUrl$element';
}
} }
} }
// print(mirrors); // print(mirror);
var data = { var data = {
'title': main?.querySelector('div[class="text-3xl font-bold"]')?.text, 'title': main?.querySelector('div[class="text-3xl font-bold"]')?.text,

View File

@ -35,17 +35,20 @@ List<String> _reorderMirrors(List<String> mirrors) {
Future<String?> _getAliveMirror(List<String> mirrors) async { Future<String?> _getAliveMirror(List<String> mirrors) async {
Dio dio = Dio(); Dio dio = Dio();
const timeOut = 15;
if (mirrors.length == 1) {
await Future.delayed(const Duration(seconds: 2));
return mirrors[0];
}
for (var url in mirrors) { for (var url in mirrors) {
try { try {
final response = await dio.head(url, final response = await dio.head(url,
options: Options(receiveTimeout: const Duration(seconds: 25))); options: Options(receiveTimeout: const Duration(seconds: timeOut)));
if (response.statusCode == 200) { if (response.statusCode == 200) {
dio.close(); dio.close();
return url; return url;
} }
} catch (_) { } catch (_) {}
// print("timeOut");
}
} }
return null; return null;
} }

View File

@ -13,7 +13,7 @@ class AboutPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const version = "1.0.10"; const version = "1.0.11";
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(

View File

@ -223,14 +223,20 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
), ),
), ),
onPressed: () async { onPressed: () async {
final result = await Navigator.push(context, if (widget.data.mirror != null &&
MaterialPageRoute(builder: (BuildContext context) { widget.data.mirror != '') {
return Webview(url: widget.data.mirror ?? ''); final result = await Navigator.push(context,
})); MaterialPageRoute(builder: (BuildContext context) {
return Webview(url: widget.data.mirror ?? '');
}));
if (result != null) { if (result != null) {
widget.data.mirror = result; await downloadFileWidget(
await downloadFileWidget(ref, context, widget.data); ref, context, widget.data, result);
}
} else {
showSnackBar(
context: context, message: 'No mirrors available!');
} }
}, },
child: const Text('Add To My Library'), child: const Text('Add To My Library'),
@ -253,16 +259,14 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
} }
} }
Future<void> downloadFileWidget( Future<void> downloadFileWidget(WidgetRef ref, BuildContext context,
WidgetRef ref, BuildContext context, BookInfoData data) async { BookInfoData data, List<String> mirrors) async {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (BuildContext context) { builder: (BuildContext context) {
return _ShowDialog(title: data.title); return _ShowDialog(title: data.title);
}); });
List<String> mirrors = [data.mirror!];
// print(mirrors); // print(mirrors);
downloadFile( downloadFile(
mirrors: mirrors, mirrors: mirrors,

View File

@ -51,21 +51,27 @@ class _WebviewState extends ConsumerState<Webview> {
}, },
onLoadStart: (controller, url) {}, onLoadStart: (controller, url) {},
onLoadStop: (controller, url) async { onLoadStop: (controller, url) async {
String query = List<String> bookDownloadLinks = [];
"""var paragraphTag=document.querySelector('p[class="mb-4 text-xl font-bold"]');var anchorTagHref=paragraphTag.querySelector('a').href;var url=()=>{return anchorTagHref};url();"""; if (url.toString().contains("slow_download")) {
String? mirrorLink = await webViewController String query =
?.evaluateJavascript(source: query); """var paragraphTag=document.querySelector('p[class="mb-4 text-xl font-bold"]');var anchorTagHref=paragraphTag.querySelector('a').href;var url=()=>{return anchorTagHref};url();""";
// final ipfsUrl = widget.url String? mirrorLink = await webViewController
// .replaceAll("slow_download", "ipfs_downloads") ?.evaluateJavascript(source: query);
// .replaceAll("/0/2", ""); if (mirrorLink != null) {
bookDownloadLinks.add(mirrorLink);
}
} else {
String query =
"""var ipfsLinkTags=document.querySelectorAll('ul>li>a');var ipfsLinks=[];var getIpfsLinks=()=>{ipfsLinkTags.forEach(e=>{ipfsLinks.push(e.href)});return ipfsLinks};getIpfsLinks();""";
List<dynamic> mirrorLinks = await webViewController
?.evaluateJavascript(source: query);
bookDownloadLinks = mirrorLinks.cast<String>();
}
// await webViewController?.loadUrl( if (bookDownloadLinks.isNotEmpty) {
// urlRequest: URLRequest(
// url: WebUri('https://example.com/new-page')));
if (mirrorLink != null) {
Future.delayed(const Duration(milliseconds: 70), () { Future.delayed(const Duration(milliseconds: 70), () {
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
Navigator.pop(context, mirrorLink); Navigator.pop(context, bookDownloadLinks);
}); });
} }
}, },

View File

@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 1.0.10+13 version: 1.0.11+14
environment: environment:
sdk: ">=3.3.0 <4.0.0" sdk: ">=3.3.0 <4.0.0"