Merge pull request #73 from shinyford/master

Add thumbnails to SearchVideo
This commit is contained in:
Mattia 2020-10-17 22:26:14 +02:00 committed by GitHub
commit 114fd3580c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -232,6 +232,7 @@ class _InitialData {
_parseRuns(renderer.title.runs),
_parseRuns(renderer.ownerText.runs),
_parseRuns(renderer.descriptionSnippet?.runs),
(renderer.thumbnail.thumbnails ?? [])..sort((a ,b) => a.width.compareTo(b.width));
renderer.lengthText?.simpleText ?? '',
int.parse(renderer.viewCountText?.simpleText
?.stripNonDigits()

View File

@ -21,9 +21,19 @@ class SearchVideo extends BaseSearchContent {
/// 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)';

View File

@ -34,6 +34,14 @@ void main() {
expect(nextPage, isNull);
});
test('Search youtube videos have thumbnails', () async {
var searchQuery = await yt.search.queryFromPage('hello');
expect(searchQuery.content.first, isA<SearchVideo>());
var video = searchQuery.content.first as SearchVideo;
expect(video.videoThumbnails, isNotEmpty);
});
test('Search youtube videos from search page (stream)', () async {
var query = await yt.search.getVideosFromPage('hello').take(30).toList();
expect(query, hasLength(30));