Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix Find Missing Books: rating parse error, improve title/ASIN matching, add disclaimer

Nathan Poulson87bf4a6f7252
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index ab2789d1..5238c344 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -1357,13 +1357,13 @@ class ApiService {
'narrators': narrators,
'releaseDate': details['release_date'] ?? '',
'runtimeMinutes': details['runtime_length_min'] ?? 0,
- 'rating': rating?['overall_distribution']?['display_average_rating']
- ?? rating?['num_reviews'] != null ? (rating?['overall_distribution']?['display_average_rating'] ?? 0.0) : 0.0,
+ 'rating': rating?['overall_distribution']?['display_average_rating'] ?? 0.0,
'numRatings': rating?['overall_distribution']?['num_ratings'] ?? 0,
'coverUrl': details['product_images']?['500'] ?? details['product_images']?['1024'] ?? '',
'sequence': book['sequence'] ?? '',
'sort': book['sort'] ?? '0',
'publisherSummary': details['publisher_summary'] ?? '',
+ 'allAsins': book['_allAsins'] ?? <String>[asin],
};
});
final batchResults = await Future.wait(futures);
diff --git a/lib/widgets/audible_series_sheet.dart b/lib/widgets/audible_series_sheet.dart
index 5b68e5e8..062792a7 100644
--- a/lib/widgets/audible_series_sheet.dart
+++ b/lib/widgets/audible_series_sheet.dart
@@ -65,19 +65,38 @@ class _AudibleSeriesSheetState extends State<AudibleSeriesSheet> {
return;
}
setState(() { _allBooks = books; _isLoading = false; });
- } catch (e) {
+ } catch (e, st) {
+ debugPrint('[AudibleSeries] discoverAudibleSeries error: $e\n$st');
if (!mounted) return;
setState(() { _isLoading = false; _error = 'Failed to load series from Audible'; });
}
}
+ static final _parenthetical = RegExp(r'\s*\([^)]*\)\s*');
+ static final _nonAlphaNum = RegExp(r'[^a-z0-9 ]');
+ static final _multiSpace = RegExp(r'\s+');
+
+ String _normalizeTitle(String title) {
+ return title
+ .toLowerCase()
+ .replaceAll(_parenthetical, ' ')
+ .replaceAll(_nonAlphaNum, ' ')
+ .replaceAll(_multiSpace, ' ')
+ .trim();
+ }
+
bool _isOwned(Map<String, dynamic> book) {
final asin = book['asin'] as String? ?? '';
if (widget.ownedAsins.contains(asin)) return true;
- // Fuzzy title match — normalize and compare
- final title = (book['title'] as String? ?? '').toLowerCase().trim();
+ // Check all regional ASIN variants
+ final allAsins = book['allAsins'] as List<dynamic>? ?? [];
+ for (final a in allAsins) {
+ if (widget.ownedAsins.contains(a)) return true;
+ }
+ final title = _normalizeTitle(book['title'] as String? ?? '');
+ if (title.isEmpty) return false;
for (final owned in widget.ownedTitles) {
- if (owned.toLowerCase().trim() == title) return true;
+ if (_normalizeTitle(owned) == title) return true;
}
return false;
}
diff --git a/lib/widgets/series_books_sheet.dart b/lib/widgets/series_books_sheet.dart
index 089adc65..1419e99e 100644
--- a/lib/widgets/series_books_sheet.dart
+++ b/lib/widgets/series_books_sheet.dart
@@ -588,6 +588,22 @@ class _SeriesBooksSheetState extends State<SeriesBooksSheet> {
}
Future<void> _findOnAudible() async {
+ final proceed = await showDialog<bool>(
+ context: context,
+ builder: (ctx) => AlertDialog(
+ title: const Text('Find Missing Books'),
+ content: const Text(
+ 'This searches Audible to find books in this series that may be missing from your library.\n\n'
+ 'Books are matched by ASIN first (depending on whether your server has ASINs for its books), '
+ 'then falls back to title matching. Results may not be perfectly accurate.'),
+ actions: [
+ TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Cancel')),
+ FilledButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('Search')),
+ ],
+ ),
+ );
+ if (proceed != true || !mounted) return;
+
// Collect owned titles and ASINs for cross-referencing
final ownedTitles = <String>{};
final ownedAsins = <String>{};