2021-02-26 16:08:48 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
|
|
|
|
import '../../youtube_explode_dart.dart';
|
2021-03-20 18:31:53 +01:00
|
|
|
import '../extensions/helpers_extension.dart';
|
2021-09-28 16:49:38 +02:00
|
|
|
import '../reverse_engineering/pages/search_page.dart';
|
2021-02-26 16:08:48 +01:00
|
|
|
|
2021-02-26 16:18:51 +01:00
|
|
|
/// This list contains search videos.
|
2021-07-24 01:30:12 +02:00
|
|
|
///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-02-26 16:08:48 +01:00
|
|
|
|
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-02-26 16:08:48 +01:00
|
|
|
|
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,
|
2021-03-24 10:40:22 +01:00
|
|
|
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
|
|
|
}
|
2021-02-26 16:08:48 +01:00
|
|
|
}
|