Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fall back to the US catalog when your Audible region has no series data

Barnabas035be257f8e6
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index af0aa099..5c794923 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -2779,14 +2779,25 @@ class ApiService {
/// Returns the raw Audnexus response including seriesPrimary, releaseDate, etc.
/// If [region] is provided, it overrides the device locale region.
static Future<Map<String, dynamic>?> getAudnexusBook(String asin, {String? region}) async {
+ final r = region ?? _region;
+ final book = await _getAudnexusBookRaw(asin, r);
+ if (book != null || r == 'us') return book;
+ // Audnexus often has no data for the smaller regional stores
+ // (REGION_UNAVAILABLE) even when that store sells the book. Series
+ // structure is the same everywhere, so fall back to the US record
+ // instead of failing the whole lookup.
+ return _getAudnexusBookRaw(asin, 'us');
+ }
+
+ static Future<Map<String, dynamic>?> _getAudnexusBookRaw(String asin, String region) async {
try {
- final r = region ?? _region;
final response = await http.get(
- Uri.parse('https://api.audnex.us/books/$asin?region=$r'),
+ Uri.parse('https://api.audnex.us/books/$asin?region=$region'),
).timeout(const Duration(seconds: 10));
if (response.statusCode == 200) {
return jsonDecode(response.body) as Map<String, dynamic>;
}
+ debugPrint('[API] getAudnexusBook $asin region=$region status=${response.statusCode}');
} catch (e) {
debugPrint('[API] getAudnexusBook error: $e');
}
@@ -2862,7 +2873,18 @@ class ApiService {
String? region,
bool newestOnly = false,
}) async {
- final relationships = await getAudibleSeriesBooks(seriesAsin, region: region);
+ var effectiveRegion = region;
+ var relationships = await getAudibleSeriesBooks(seriesAsin, region: region);
+ if (relationships.isEmpty && region != null && region != 'us') {
+ // Regional stores often lack the series ASIN even when they sell the
+ // books - US data beats no data. Details must then come from the US
+ // store too, since these relationship ASINs may not exist regionally.
+ relationships = await getAudibleSeriesBooks(seriesAsin, region: 'us');
+ if (relationships.isNotEmpty) {
+ debugPrint('[API] discoverAudibleSeries: region $region empty, using us');
+ effectiveRegion = 'us';
+ }
+ }
if (relationships.isEmpty) return [];
final bySequence = <String, List<Map<String, dynamic>>>{};
@@ -2899,7 +2921,7 @@ class ApiService {
final batch = uniqueBooks.skip(i).take(10);
final futures = batch.map((book) async {
final asin = book['asin'] as String;
- final details = await getAudibleBookDetails(asin, region: region);
+ final details = await getAudibleBookDetails(asin, region: effectiveRegion);
if (details == null) return null;
final authors = (details['authors'] as List<dynamic>? ?? [])