scrapeAllPages method

Future<void> scrapeAllPages({
  1. required int latestTotalPages,
  2. required int cachedTotalPages,
})

Implementation

Future<void> scrapeAllPages({
  required int latestTotalPages,
  required int cachedTotalPages,
}) async {
  int count = 0;
  for (int page = latestTotalPages - cachedTotalPages; page >= 1; page--) {
    print('Scraping page $page');
    await AudioBookBayApi()
        .find(SearchRequest(query: '', page: page))
        .then((response) async {
      for (final book in response.books) {
        // print(book.title);
        await compute(saveAudiobook, book);
      }
    });

    count += 1;
    final save = await updateSyncHistory(
      AudioBookSyncHistory(totalPages: cachedTotalPages + count),
    );
    if (!save) {
      print('Failed to save sync history');
      break;
    }
  }
}