youtube_explode/lib/src/search/search_list.dart

33 lines
1021 B
Dart
Raw Normal View History

import 'dart:async';
import 'package:collection/collection.dart';
2021-03-20 18:31:53 +01:00
import 'package:youtube_explode_dart/src/reverse_engineering/responses/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.
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-03-20 18:31:53 +01:00
SearchList(List<Video> base, this._page, this._httpClient) : super(base);
///
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(
page.initialData.searchContent
.whereType<SearchVideo>()
.map((e) => Video(e.id, e.title, e.author, null, e.uploadDate.toDateTime(), e.description, e.duration.toDuration(),
ThumbnailSet(e.id.value), null, Engagement(e.viewCount, null, null), e.isLive))
.toList(),
page,
_httpClient);
2021-02-27 18:58:42 +01:00
}
}