ArchiveApi class provides methods to query the Archive.org API for LibriVox audiobooks with support for language filtering, genre categorization, and search functionality.
Overview
This service handles:- Fetching latest, most viewed, and most downloaded audiobooks
- Genre-based filtering with multi-language support
- Search functionality with language preferences
- HTTP caching with ETags and conditional requests
- Multi-language subject indexing for improved categorization
lib/resources/archive_api.dart
Public Methods
getLatestAudiobook
Fetches the most recently added audiobooks from the LibriVox collection.Page number for pagination (1-based)
Number of results per page
Future<Either<String, List<Audiobook>>>
Example:
getMostViewedWeeklyAudiobook
Retrieves audiobooks sorted by weekly view count.Page number for pagination
Number of results per page
Future<Either<String, List<Audiobook>>>
Example:
getMostDownloadedEverAudiobook
Fetches audiobooks sorted by total download count.Page number for pagination
Number of results per page
Future<Either<String, List<Audiobook>>>
Example:
getAudiobooksByGenre
Fetches audiobooks filtered by genre with support for multi-language subjects.Genre identifier (e.g., ‘mystery’, ‘scifi’, ‘romance’). Supports OR queries.
Page number for pagination
Number of results per page
Sort field (e.g., ‘downloads’, ‘week’, ‘addeddate’)
Future<Either<String, List<Audiobook>>>
Example:
getAudiobookFiles
Retrieves the audio files and metadata for a specific audiobook.Archive.org identifier for the audiobook
Future<Either<String, List<AudiobookFile>>>
The method extracts:
- Audio track files with original source
- High-quality cover images (JPEG format)
- Track numbers and metadata
searchAudiobook
Searches for audiobooks using a free-form query string with language filtering.Search terms (will be URI encoded)
Page number for pagination
Number of results per page
Future<Either<String, List<Audiobook>>>
Example:
Language Support
TheArchiveApi automatically applies language filters based on user preferences stored in Hive (language_prefs_box). Supported languages include:
- English (en), German (de), Spanish (es), French (fr)
- Dutch (nl), Portuguese (pt), Italian (it), Russian (ru)
- Greek (el), Japanese (ja), Polish (pl), Chinese (zh)
- Hebrew (he), Latin (la), Finnish (fi), Swedish (sv)
- Catalan (ca), Danish (da), Esperanto (eo)
- And more (see
_langAliasesmapping in source)
HTTP Caching
The service implements HTTP caching with:- ETag-based conditional requests
- Last-Modified headers
- 15-minute staleness window
- LRU cache eviction (max 100 entries)
Genre Filtering
Genre filtering uses comprehensive regex-based category filters across multiple languages. Available genres include:war,adventure,biography,children,comedycrime,fantasy,horror,love,mysteryphilosophy,poem,religion,romance,scifi