Thumbnail for playlists

This commit is contained in:
Hexah 2020-06-30 15:00:00 +02:00
parent 0d16e9613b
commit 6fb757e726
4 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,7 @@
## 1.4.0
- Add ChannelId property to Video class.
- Implement `thumbnails` for playlists. The playlist's thumbnail is the same as the thumbnail of its first video. If the playlist is empty, then this property is `null`.
- Update for age restricted videos.
## 1.3.3
- Error handling when using `getStream` if the connection fails. If it fails more than 5 times on the same request the exception will be thrown anyways.

View File

@ -21,11 +21,16 @@ class Playlist with EquatableMixin {
/// Playlist description.
final String description;
/// Available thumbnails for this playlist.
/// Can be null if the playlist is empty.
final ThumbnailSet thumbnails;
/// Engagement statistics.
final Engagement engagement;
/// Initializes an instance of [Playlist].
Playlist(this.id, this.title, this.author, this.description, this.engagement);
Playlist(this.id, this.title, this.author, this.description, this.thumbnails,
this.engagement);
@override
String toString() => 'Playlist ($title)';

View File

@ -23,6 +23,7 @@ class PlaylistClient {
response.title,
response.author,
response.description ?? '',
response.thumbnails,
Engagement(response.viewCount ?? 0, response.likeCount ?? 0,
response.dislikeCount ?? 0));
}

View File

@ -1,5 +1,7 @@
import 'dart:convert';
import 'package:youtube_explode_dart/src/common/common.dart';
import '../../channels/channel_id.dart';
import '../../exceptions/exceptions.dart';
import '../../extensions/helpers_extension.dart';
@ -7,6 +9,8 @@ import '../../retry.dart';
import '../youtube_http_client.dart';
class PlaylistResponse {
Iterable<_Video> _videos;
// Json parsed map
final Map<String, dynamic> _root;
@ -16,13 +20,15 @@ class PlaylistResponse {
String get description => _root['description'];
ThumbnailSet get thumbnails => ThumbnailSet(videos.firstOrNull.id);
int get viewCount => _root['views'];
int get likeCount => _root['likes'];
int get dislikeCount => _root['dislikes'];
Iterable<_Video> get videos =>
Iterable<_Video> get videos => _videos ??=
_root['video']?.map((e) => _Video(e))?.cast<_Video>() ?? const <_Video>[];
PlaylistResponse(this._root);