updateAudiobookDetails method

Future<void> updateAudiobookDetails()

Implementation

Future<void> updateAudiobookDetails() async {
  final results = await pb
      .collection('audiobooks')
      .getList(page: 1, perPage: 500, filter: 'hash = null');

  for (final record in results.items) {
    try {
      final detailUrl = record.data['detailUrl'].toString();
      final detailInfo = await scrapeAudiobookDetails(detailUrl);

      await pb.collection('audiobooks').update(record.id, body: {
        'hash': detailInfo['hash'],
        'downloadLink': detailInfo['downloadLink']
      });

      await Future<void>.delayed(
          const Duration(seconds: 2)); // Be nice to server
    } catch (e) {
      print('Error updating audiobook details: $e');
    }
  }
}