diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e750aa..05b6ec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/src/playlists/playlist.dart b/lib/src/playlists/playlist.dart index b5db5e7..d6022d9 100644 --- a/lib/src/playlists/playlist.dart +++ b/lib/src/playlists/playlist.dart @@ -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)'; diff --git a/lib/src/playlists/playlist_client.dart b/lib/src/playlists/playlist_client.dart index 1deaecc..b9b14fe 100644 --- a/lib/src/playlists/playlist_client.dart +++ b/lib/src/playlists/playlist_client.dart @@ -23,6 +23,7 @@ class PlaylistClient { response.title, response.author, response.description ?? '', + response.thumbnails, Engagement(response.viewCount ?? 0, response.likeCount ?? 0, response.dislikeCount ?? 0)); } diff --git a/lib/src/reverse_engineering/responses/playlist_response.dart b/lib/src/reverse_engineering/responses/playlist_response.dart index 452120d..4682803 100644 --- a/lib/src/reverse_engineering/responses/playlist_response.dart +++ b/lib/src/reverse_engineering/responses/playlist_response.dart @@ -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 _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);