Skip to content

Commit bfad3f9

Browse files
committed
Fixed 'stuck in solve captcha screen'
1 parent a363a88 commit bfad3f9

File tree

6 files changed

+67
-63
lines changed

6 files changed

+67
-63
lines changed

lib/services/annas_archieve.dart

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,52 +162,43 @@ class AnnasArchieve {
162162
Future<BookInfoData?> _bookInfoParser(resData, url) async {
163163
var document = parse(resData.toString());
164164
var main = document.querySelector('main[class="main"]');
165-
var ul = main?.querySelectorAll('ul[class="list-inside mb-4 ml-1"]');
165+
var ul = main?.querySelectorAll('ul[class="list-inside mb-4 ml-1"]>li>a');
166+
var externalUrlAnchorTags = main
167+
?.querySelector(
168+
'ul[class="list-inside mb-4 ml-1 js-show-external hidden"]')
169+
?.querySelectorAll('li>a');
166170

167171
// List<String> mirrors = [];
168-
169-
// if (ul != null) {
170-
// var anchorTags = [];
171-
172-
// for (var e in ul) {
173-
// anchorTags.insertAll(0, e.querySelectorAll('a'));
174-
// }
175-
176-
// for (var element in anchorTags) {
177-
// if (element.attributes['href'] != null &&
178-
// element.attributes['href']!.startsWith('/slow_download') &&
179-
// element.attributes['href']!.endsWith('/2')) {
180-
// String? url =
181-
// await _getMirrorLink('$baseUrl${element.attributes['href']!}');
182-
// if (url != null && url.isNotEmpty) {
183-
// mirrors.add(url);
184-
// }
185-
// } else if (element.attributes['href']!.startsWith('https://')) {
186-
// if (element.attributes['href'] != null &&
187-
// element.attributes['href'].contains('ipfs') == true) {
188-
// mirrors.add(element.attributes['href']!);
189-
// }
190-
// }
191-
// }
192-
// }
193172
String? mirror;
194173
var anchorTags = [];
195174

196175
if (ul != null) {
197-
for (var e in ul) {
198-
anchorTags.insertAll(0, e.querySelectorAll('a'));
176+
for (var element in ul) {
177+
if (element.attributes['href'] != null &&
178+
element.attributes['href']!.startsWith('/slow_download') &&
179+
element.attributes['href']!.endsWith('/2')) {
180+
mirror = '$baseUrl${element.attributes['href']}';
181+
}
199182
}
200183
}
201184

202-
for (var element in anchorTags) {
203-
if (element.attributes['href'] != null &&
204-
element.attributes['href']!.startsWith('/slow_download') &&
205-
element.attributes['href']!.endsWith('/2')) {
206-
mirror = '$baseUrl${element.attributes['href']}';
185+
if (mirror == null) {
186+
if (externalUrlAnchorTags != null) {
187+
for (var e in externalUrlAnchorTags) {
188+
if (e.attributes['href'] != null) {
189+
anchorTags.add(e.attributes['href']);
190+
}
191+
}
192+
}
193+
194+
for (var element in anchorTags) {
195+
if (element.startsWith('/ipfs_downloads')) {
196+
mirror = '$baseUrl$element';
197+
}
207198
}
208199
}
209200

210-
// print(mirrors);
201+
// print(mirror);
211202

212203
var data = {
213204
'title': main?.querySelector('div[class="text-3xl font-bold"]')?.text,

lib/services/download_file.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ List<String> _reorderMirrors(List<String> mirrors) {
3535

3636
Future<String?> _getAliveMirror(List<String> mirrors) async {
3737
Dio dio = Dio();
38+
const timeOut = 15;
39+
if (mirrors.length == 1) {
40+
await Future.delayed(const Duration(seconds: 2));
41+
return mirrors[0];
42+
}
3843
for (var url in mirrors) {
3944
try {
4045
final response = await dio.head(url,
41-
options: Options(receiveTimeout: const Duration(seconds: 25)));
46+
options: Options(receiveTimeout: const Duration(seconds: timeOut)));
4247
if (response.statusCode == 200) {
4348
dio.close();
4449
return url;
4550
}
46-
} catch (_) {
47-
// print("timeOut");
48-
}
51+
} catch (_) {}
4952
}
5053
return null;
5154
}

lib/ui/about_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AboutPage extends StatelessWidget {
1313

1414
@override
1515
Widget build(BuildContext context) {
16-
const version = "1.0.10";
16+
const version = "1.0.11";
1717

1818
return Scaffold(
1919
appBar: AppBar(

lib/ui/book_info_page.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,20 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
223223
),
224224
),
225225
onPressed: () async {
226-
final result = await Navigator.push(context,
227-
MaterialPageRoute(builder: (BuildContext context) {
228-
return Webview(url: widget.data.mirror ?? '');
229-
}));
226+
if (widget.data.mirror != null &&
227+
widget.data.mirror != '') {
228+
final result = await Navigator.push(context,
229+
MaterialPageRoute(builder: (BuildContext context) {
230+
return Webview(url: widget.data.mirror ?? '');
231+
}));
230232

231-
if (result != null) {
232-
widget.data.mirror = result;
233-
await downloadFileWidget(ref, context, widget.data);
233+
if (result != null) {
234+
await downloadFileWidget(
235+
ref, context, widget.data, result);
236+
}
237+
} else {
238+
showSnackBar(
239+
context: context, message: 'No mirrors available!');
234240
}
235241
},
236242
child: const Text('Add To My Library'),
@@ -253,16 +259,14 @@ class _ActionButtonWidgetState extends ConsumerState<ActionButtonWidget> {
253259
}
254260
}
255261

256-
Future<void> downloadFileWidget(
257-
WidgetRef ref, BuildContext context, BookInfoData data) async {
262+
Future<void> downloadFileWidget(WidgetRef ref, BuildContext context,
263+
BookInfoData data, List<String> mirrors) async {
258264
showDialog(
259265
context: context,
260266
barrierDismissible: false,
261267
builder: (BuildContext context) {
262268
return _ShowDialog(title: data.title);
263269
});
264-
265-
List<String> mirrors = [data.mirror!];
266270
// print(mirrors);
267271
downloadFile(
268272
mirrors: mirrors,

lib/ui/webview_page.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,27 @@ class _WebviewState extends ConsumerState<Webview> {
5151
},
5252
onLoadStart: (controller, url) {},
5353
onLoadStop: (controller, url) async {
54-
String query =
55-
"""var paragraphTag=document.querySelector('p[class="mb-4 text-xl font-bold"]');var anchorTagHref=paragraphTag.querySelector('a').href;var url=()=>{return anchorTagHref};url();""";
56-
String? mirrorLink = await webViewController
57-
?.evaluateJavascript(source: query);
58-
// final ipfsUrl = widget.url
59-
// .replaceAll("slow_download", "ipfs_downloads")
60-
// .replaceAll("/0/2", "");
54+
List<String> bookDownloadLinks = [];
55+
if (url.toString().contains("slow_download")) {
56+
String query =
57+
"""var paragraphTag=document.querySelector('p[class="mb-4 text-xl font-bold"]');var anchorTagHref=paragraphTag.querySelector('a').href;var url=()=>{return anchorTagHref};url();""";
58+
String? mirrorLink = await webViewController
59+
?.evaluateJavascript(source: query);
60+
if (mirrorLink != null) {
61+
bookDownloadLinks.add(mirrorLink);
62+
}
63+
} else {
64+
String query =
65+
"""var ipfsLinkTags=document.querySelectorAll('ul>li>a');var ipfsLinks=[];var getIpfsLinks=()=>{ipfsLinkTags.forEach(e=>{ipfsLinks.push(e.href)});return ipfsLinks};getIpfsLinks();""";
66+
List<dynamic> mirrorLinks = await webViewController
67+
?.evaluateJavascript(source: query);
68+
bookDownloadLinks = mirrorLinks.cast<String>();
69+
}
6170

62-
// await webViewController?.loadUrl(
63-
// urlRequest: URLRequest(
64-
// url: WebUri('https://example.com/new-page')));
65-
if (mirrorLink != null) {
71+
if (bookDownloadLinks.isNotEmpty) {
6672
Future.delayed(const Duration(milliseconds: 70), () {
6773
// ignore: use_build_context_synchronously
68-
Navigator.pop(context, mirrorLink);
74+
Navigator.pop(context, bookDownloadLinks);
6975
});
7076
}
7177
},

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
1616
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1717
# In Windows, build-name is used as the major, minor, and patch parts
1818
# of the product and file versions while build-number is used as the build suffix.
19-
version: 1.0.10+13
19+
version: 1.0.11+14
2020

2121
environment:
2222
sdk: ">=3.3.0 <4.0.0"

0 commit comments

Comments
 (0)