mirror of
https://github.com/dstark5/Openlib.git
synced 2025-07-03 13:06:47 +08:00
Fixed trending page request connection error
This commit is contained in:
@ -8,9 +8,31 @@ class TrendingBookData {
|
|||||||
TrendingBookData({this.title, this.thumbnail});
|
TrendingBookData({this.title, this.thumbnail});
|
||||||
}
|
}
|
||||||
|
|
||||||
class OpenLibrary {
|
abstract class TrendingBooksImpl {
|
||||||
String url = "https://openlibrary.org/trending/daily";
|
String url = '';
|
||||||
|
int timeOutDuration = 20;
|
||||||
|
List<TrendingBookData> _parser(dynamic data);
|
||||||
|
|
||||||
|
Future<List<TrendingBookData>> trendingBooks() async {
|
||||||
|
try {
|
||||||
|
final dio = Dio();
|
||||||
|
final response = await dio.get(url,
|
||||||
|
options: Options(
|
||||||
|
sendTimeout: Duration(seconds: timeOutDuration),
|
||||||
|
receiveTimeout: Duration(seconds: timeOutDuration)));
|
||||||
|
return _parser(response.data.toString());
|
||||||
|
} on DioException catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OpenLibrary extends TrendingBooksImpl {
|
||||||
|
OpenLibrary() {
|
||||||
|
super.url = "https://openlibrary.org/trending/daily";
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
List<TrendingBookData> _parser(data) {
|
List<TrendingBookData> _parser(data) {
|
||||||
var document = parse(data.toString());
|
var document = parse(data.toString());
|
||||||
var bookList = document.querySelectorAll('li[class="searchResultItem"]');
|
var bookList = document.querySelectorAll('li[class="searchResultItem"]');
|
||||||
@ -32,32 +54,33 @@ class OpenLibrary {
|
|||||||
return trendingBooks;
|
return trendingBooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
Future<List<TrendingBookData>> trendingBooks() async {
|
Future<List<TrendingBookData>> trendingBooks() async {
|
||||||
try {
|
try {
|
||||||
final dio = Dio();
|
final dio = Dio();
|
||||||
|
const timeOutDuration = 5;
|
||||||
final response = await dio.get(url,
|
final response = await dio.get(url,
|
||||||
options: Options(
|
options: Options(
|
||||||
sendTimeout: const Duration(seconds: 20),
|
sendTimeout: const Duration(seconds: timeOutDuration),
|
||||||
receiveTimeout: const Duration(seconds: 20)));
|
receiveTimeout: const Duration(seconds: timeOutDuration)));
|
||||||
final response2 = await dio.get(
|
final response2 = await dio.get(
|
||||||
"https://openlibrary.org/trending/daily?page=2",
|
"https://openlibrary.org/trending/daily?page=2",
|
||||||
options: Options(
|
options: Options(
|
||||||
sendTimeout: const Duration(seconds: 20),
|
sendTimeout: const Duration(seconds: timeOutDuration),
|
||||||
receiveTimeout: const Duration(seconds: 20)));
|
receiveTimeout: const Duration(seconds: timeOutDuration)));
|
||||||
return _parser('${response.data.toString()}${response2.data.toString()}');
|
return _parser('${response.data.toString()}${response2.data.toString()}');
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
return [];
|
return [];
|
||||||
// if (e.type == DioExceptionType.unknown) {
|
|
||||||
// throw "socketException";
|
|
||||||
// }
|
|
||||||
// rethrow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GoodReads {
|
class GoodReads extends TrendingBooksImpl {
|
||||||
String url = "https://www.goodreads.com/shelf/show/trending";
|
GoodReads() {
|
||||||
|
super.url = "https://www.goodreads.com/shelf/show/trending";
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
List<TrendingBookData> _parser(data) {
|
List<TrendingBookData> _parser(data) {
|
||||||
var document = parse(data.toString());
|
var document = parse(data.toString());
|
||||||
var bookList = document.querySelectorAll('div[class="elementList"]');
|
var bookList = document.querySelectorAll('div[class="elementList"]');
|
||||||
@ -85,29 +108,15 @@ class GoodReads {
|
|||||||
}
|
}
|
||||||
return trendingBooks;
|
return trendingBooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<TrendingBookData>> trendingBooks() async {
|
|
||||||
try {
|
|
||||||
final dio = Dio();
|
|
||||||
final response = await dio.get(url,
|
|
||||||
options: Options(
|
|
||||||
sendTimeout: const Duration(seconds: 20),
|
|
||||||
receiveTimeout: const Duration(seconds: 20)));
|
|
||||||
return _parser(response.data.toString());
|
|
||||||
} on DioException catch (e) {
|
|
||||||
return [];
|
|
||||||
// if (e.type == DioExceptionType.unknown) {
|
|
||||||
// throw "socketException";
|
|
||||||
// }
|
|
||||||
// rethrow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PenguinRandomHouse {
|
class PenguinRandomHouse extends TrendingBooksImpl {
|
||||||
String url =
|
PenguinRandomHouse() {
|
||||||
"https://www.penguinrandomhouse.com/ajaxc/categories/books/?from=0&to=50&contentId=&elClass=book&dataType=html&catFilter=best-sellers";
|
super.url =
|
||||||
|
"https://www.penguinrandomhouse.com/ajaxc/categories/books/?from=0&to=50&contentId=&elClass=book&dataType=html&catFilter=best-sellers";
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
List<TrendingBookData> _parser(data) {
|
List<TrendingBookData> _parser(data) {
|
||||||
var document = parse(data.toString());
|
var document = parse(data.toString());
|
||||||
var bookList = document.querySelectorAll('div[class="book"]');
|
var bookList = document.querySelectorAll('div[class="book"]');
|
||||||
@ -134,21 +143,34 @@ class PenguinRandomHouse {
|
|||||||
}
|
}
|
||||||
return trendingBooks;
|
return trendingBooks;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<TrendingBookData>> trendingBooks() async {
|
class BookDigits extends TrendingBooksImpl {
|
||||||
try {
|
BookDigits() {
|
||||||
final dio = Dio();
|
super.url = "https://bookdigits.com/fresh";
|
||||||
final response = await dio.get(url,
|
}
|
||||||
options: Options(
|
|
||||||
sendTimeout: const Duration(seconds: 20),
|
@override
|
||||||
receiveTimeout: const Duration(seconds: 20)));
|
List<TrendingBookData> _parser(data) {
|
||||||
return _parser(response.data.toString());
|
var document = parse(data.toString());
|
||||||
} on DioException catch (e) {
|
var bookList = document.querySelectorAll('div[class="list-row"]');
|
||||||
return [];
|
List<TrendingBookData> trendingBooks = [];
|
||||||
// if (e.type == DioExceptionType.unknown) {
|
for (var element in bookList) {
|
||||||
// throw "socketException";
|
if (element.querySelector('div[class="list-title link-reg"]')?.text !=
|
||||||
// }
|
null &&
|
||||||
// rethrow;
|
element.querySelector('img')?.attributes['src'] != null) {
|
||||||
|
String? thumbnail = element.querySelector('img')?.attributes['src'];
|
||||||
|
trendingBooks.add(
|
||||||
|
TrendingBookData(
|
||||||
|
title: element
|
||||||
|
.querySelector('div[class="list-title link-reg"]')
|
||||||
|
?.text
|
||||||
|
.toString()
|
||||||
|
.trim(),
|
||||||
|
thumbnail: thumbnail.toString()),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return trendingBooks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,20 +72,22 @@ final searchQueryProvider = StateProvider<String>((ref) => "");
|
|||||||
//Provider for Trending Books
|
//Provider for Trending Books
|
||||||
|
|
||||||
final getTrendingBooks = FutureProvider<List<TrendingBookData>>((ref) async {
|
final getTrendingBooks = FutureProvider<List<TrendingBookData>>((ref) async {
|
||||||
OpenLibrary openLibrary = OpenLibrary();
|
// OpenLibrary openLibrary = OpenLibrary();
|
||||||
GoodReads goodReads = GoodReads();
|
GoodReads goodReads = GoodReads();
|
||||||
PenguinRandomHouse penguinTrending = PenguinRandomHouse();
|
PenguinRandomHouse penguinTrending = PenguinRandomHouse();
|
||||||
|
BookDigits bookDigits = BookDigits();
|
||||||
List<TrendingBookData> trendingBooks =
|
List<TrendingBookData> trendingBooks =
|
||||||
await Future.wait<List<TrendingBookData>>([
|
await Future.wait<List<TrendingBookData>>([
|
||||||
goodReads.trendingBooks(),
|
goodReads.trendingBooks(),
|
||||||
penguinTrending.trendingBooks(),
|
penguinTrending.trendingBooks(),
|
||||||
openLibrary.trendingBooks(),
|
// openLibrary.trendingBooks(),
|
||||||
|
bookDigits.trendingBooks(),
|
||||||
]).then((List<List<TrendingBookData>> listOfData) =>
|
]).then((List<List<TrendingBookData>> listOfData) =>
|
||||||
listOfData.expand((element) => element).toList());
|
listOfData.expand((element) => element).toList());
|
||||||
|
|
||||||
if(trendingBooks.isEmpty){
|
if (trendingBooks.isEmpty) {
|
||||||
throw 'Nothing Trending Today :(';
|
throw 'Nothing Trending Today :(';
|
||||||
}
|
}
|
||||||
trendingBooks.shuffle();
|
trendingBooks.shuffle();
|
||||||
return trendingBooks;
|
return trendingBooks;
|
||||||
});
|
});
|
||||||
|
@ -13,6 +13,8 @@ class AboutPage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
const version = "1.0.9";
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.background,
|
backgroundColor: Theme.of(context).colorScheme.background,
|
||||||
@ -47,7 +49,7 @@ class AboutPage extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(left: 7, right: 7, top: 5),
|
padding: EdgeInsets.only(left: 7, right: 7, top: 5),
|
||||||
child: Text(
|
child: Text(
|
||||||
"1.0.8",
|
version,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
@ -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.8+11
|
version: 1.0.9+12
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.3.0 <4.0.0"
|
sdk: ">=3.3.0 <4.0.0"
|
||||||
@ -36,6 +36,7 @@ dependencies:
|
|||||||
|
|
||||||
flutter_pdfview: ^1.2.7
|
flutter_pdfview: ^1.2.7
|
||||||
epub_view: ^3.2.0
|
epub_view: ^3.2.0
|
||||||
|
# vocsy_epub_viewer: ^3.0.0
|
||||||
# syncfusion_flutter_pdfviewer: ^22.2.5
|
# syncfusion_flutter_pdfviewer: ^22.2.5
|
||||||
# pdfx: ^2.4.0
|
# pdfx: ^2.4.0
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user