Skip to main content

Overview

The Audiobook class represents an audiobook retrieved from LibriVox via the Archive.org API. It contains metadata such as title, author, description, ratings, and more.

Properties

title
String
required
The title of the audiobook
id
String
required
The unique identifier for the audiobook (Archive.org identifier)
description
String?
A text description of the audiobook
totalTime
String?
The total runtime of the audiobook
author
String?
The author or creator of the audiobook
date
DateTime?
The publication or upload date
downloads
int?
The number of times the audiobook has been downloaded
subject
List<dynamic>?
A list of subject tags or categories for the audiobook. Filters out generic tags like “librivox”, “audiobooks”, and “audiobook”
size
int?
The total size of the audiobook in bytes
rating
double?
The average user rating for the audiobook
reviews
int?
The number of reviews the audiobook has received
lowQCoverImage
String
required
URL to the audiobook cover image. Constructed from Archive.org’s image service using the identifier
language
String?
The language code of the audiobook (e.g., “en” for English)
origin
String?
The source of the audiobook (typically “librivox”)

Constructors

Audiobook.empty()

Creates an empty audiobook instance with default values.
Audiobook emptyBook = Audiobook.empty();
// Returns an Audiobook with empty strings and zero values

Audiobook.fromJson(Map jsonAudiobook)

Creates an Audiobook instance from a JSON map retrieved from the Archive.org API. Parameters:
jsonAudiobook
Map
required
A map containing audiobook data from the Archive.org API response
JSON Field Mappings:
  • identifierid
  • titletitle
  • runtimetotalTime
  • creatorauthor (defaults to “Unknown”)
  • datedate (parsed to DateTime)
  • downloadsdownloads
  • subjectsubject (filtered)
  • item_sizesize
  • avg_ratingrating
  • num_reviewsreviews
  • descriptiondescription
  • languagelanguage (defaults to “en”)
Map<String, dynamic> jsonData = {
  "identifier": "book123",
  "title": "Pride and Prejudice",
  "creator": "Jane Austen",
  "runtime": "11:00:00",
  "downloads": 5000,
  "avg_rating": "4.5"
};

Audiobook book = Audiobook.fromJson(jsonData);

Audiobook.fromMap

Creates an Audiobook instance from a map (typically used for local storage retrieval). Parameters:
map
Map
required
A map containing audiobook data in the internal format (Map<dynamic, dynamic>)
Map<String, dynamic> map = {
  "id": "book123",
  "title": "Pride and Prejudice",
  "author": "Jane Austen",
  "date": "2020-01-01T00:00:00.000Z",
  "rating": "4.5"
};

Audiobook book = Audiobook.fromMap(map);

Methods

toMap()

Converts the audiobook to a map suitable for storage. Returns: Map<dynamic, dynamic>
Audiobook book = Audiobook.fromJson(jsonData);
Map<dynamic, dynamic> map = book.toMap();

toJson()

Converts the audiobook to a JSON-serializable map. Returns: Map<String, dynamic>
Audiobook book = Audiobook.fromJson(jsonData);
Map<String, dynamic> json = book.toJson();

copyWith

Creates a copy of the audiobook with optionally updated fields. Parameters:
title
String?
Updated title
id
String?
Updated identifier
description
String?
Updated description
totalTime
String?
Updated total time
author
String?
Updated author
date
DateTime?
Updated date
downloads
int?
Updated download count
subject
List<String>?
Updated subject list
size
int?
Updated size
rating
double?
Updated rating
reviews
int?
Updated review count
lowQCoverImage
String?
Updated cover image URL
language
String?
Updated language code
origin
String?
Updated origin
Returns: Audiobook
Audiobook book = Audiobook.fromJson(jsonData);
Audiobook updatedBook = book.copyWith(
  rating: 5.0,
  downloads: 6000
);

Static Methods

fromJsonArray(List jsonAudiobook)

Converts a list of JSON objects into a list of Audiobook instances. Filters out invalid entries (thumbs, librivox creators, null titles). Parameters:
jsonAudiobook
List
required
A list of JSON maps from the API response
Returns: List<Audiobook>
List<dynamic> jsonArray = [
  {"identifier": "book1", "title": "Book One", "creator": "Author One"},
  {"identifier": "book2", "title": "Book Two", "creator": "Author Two"}
];

List<Audiobook> audiobooks = Audiobook.fromJsonArray(jsonArray);

Build docs developers (and LLMs) love