Add video thumbnails to SearchVideo

This commit is contained in:
Nic Ford 2020-09-23 07:27:23 +01:00
parent 4646f484b8
commit 4047117eba
2 changed files with 20 additions and 4 deletions

View File

@ -205,6 +205,11 @@ class _InitialData {
}
if (content.containsKey('videoRenderer')) {
Map<String, dynamic> renderer = content['videoRenderer'];
final thumbnails = List<Map<String, dynamic>>.from(
renderer.get('thumbnail')?.getValue('thumbnails') ?? []
)..sort((a, b) => a['width'].compareTo(b['width']));
//TODO: Add if it's a live
return SearchVideo(
VideoId(renderer['videoId']),
@ -215,8 +220,9 @@ class _InitialData {
int.parse(renderer['viewCountText']['simpleText']
.toString()
.stripNonDigits()
.nullIfWhitespace ??
'0'));
.nullIfWhitespace ?? '0'),
thumbnails.map<String>((thumb) => thumb['url']).toList(growable: false)
);
}
if (content.containsKey('radioRenderer')) {
var renderer = content['radioRenderer'];

View File

@ -20,9 +20,19 @@ class SearchVideo {
/// Video View Count
final int videoViewCount;
/// Video thumbnail uris
final List<String> videoThumbnails;
/// Initialize a [SearchVideo] instance.
const SearchVideo(this.videoId, this.videoTitle, this.videoAuthor,
this.videoDescriptionSnippet, this.videoDuration, this.videoViewCount);
const SearchVideo(
this.videoId,
this.videoTitle,
this.videoAuthor,
this.videoDescriptionSnippet,
this.videoDuration,
this.videoViewCount,
this.videoThumbnails,
);
@override
String toString() => '(Video) $videoTitle ($videoId)';