youtube_explode/lib/src/search/search_list.dart

47 lines
1.4 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'package:collection/collection.dart';
2021-07-21 02:06:02 +02:00
import 'package:youtube_explode_dart/src/reverse_engineering/pages/search_page.dart';
import '../../youtube_explode_dart.dart';
2021-03-20 18:31:53 +01:00
import '../extensions/helpers_extension.dart';
2021-02-26 16:18:51 +01:00
/// This list contains search videos.
///This behaves like a [List] but has the [SearchList.nextPage] to get the next batch of videos.
2021-02-27 18:58:42 +01:00
class SearchList extends DelegatingList<Video> {
2021-03-20 18:31:53 +01:00
final SearchPage _page;
final YoutubeHttpClient _httpClient;
2021-04-30 23:49:49 +02:00
/// Construct an instance of [SearchList]
/// See [SearchList]
2021-03-20 18:31:53 +01:00
SearchList(List<Video> base, this._page, this._httpClient) : super(base);
2021-04-30 23:49:49 +02:00
/// Fetches the next batch of videos or returns null if there are no more
/// results.
2021-03-20 18:31:53 +01:00
Future<SearchList?> nextPage() async {
final page = await _page.nextPage(_httpClient);
if (page == null) {
2021-02-27 18:58:42 +01:00
return null;
}
2021-03-20 18:31:53 +01:00
return SearchList(
2021-08-31 18:06:34 +02:00
page.searchContent
2021-03-20 18:31:53 +01:00
.whereType<SearchVideo>()
2021-03-24 06:17:49 +01:00
.map((e) => Video(
e.id,
e.title,
e.author,
ChannelId(e.channelId),
2021-03-24 06:17:49 +01:00
e.uploadDate.toDateTime(),
null,
e.description,
e.duration.toDuration(),
ThumbnailSet(e.id.value),
null,
Engagement(e.viewCount, null, null),
e.isLive))
2021-03-20 18:31:53 +01:00
.toList(),
page,
_httpClient);
2021-02-27 18:58:42 +01:00
}
}