From 24147692a24adbe5acffb63d7e68fa34f81b46e7 Mon Sep 17 00:00:00 2001 From: mitchpk Date: Sat, 16 Oct 2021 17:17:24 +1030 Subject: [PATCH] fix playlist parsing --- .../pages/search_page.dart | 22 +++-- lib/src/search/search_client.dart | 2 +- lib/src/search/search_playlist.dart | 6 +- lib/src/search/search_playlist.freezed.dart | 91 +++++++++++++------ 4 files changed, 81 insertions(+), 40 deletions(-) diff --git a/lib/src/reverse_engineering/pages/search_page.dart b/lib/src/reverse_engineering/pages/search_page.dart index cd3938f..9c8cf9e 100644 --- a/lib/src/reverse_engineering/pages/search_page.dart +++ b/lib/src/reverse_engineering/pages/search_page.dart @@ -191,16 +191,22 @@ class _InitialData extends InitialData { renderer['ownerText']['runs'][0]['navigationEndpoint'] ['browseEndpoint']['browseId']); } - if (content['radioRenderer'] != null) { - var renderer = content.get('radioRenderer')!; + if (content['radioRenderer'] != null || + content['playlistRenderer'] != null) { + var renderer = + (content.get('radioRenderer') ?? content.get('playlistRenderer'))!; return SearchPlaylist( - PlaylistId(renderer.getT('playlistId')!), - renderer.get('title')!.getT('simpleText')!, - int.parse(_parseRuns(renderer.get('videoCountText')?.getList('runs')) - .stripNonDigits() - .nullIfWhitespace ?? - '0')); + PlaylistId(renderer.getT('playlistId')!), + renderer.get('title')!.getT('simpleText')!, + int.parse(_parseRuns(renderer.get('videoCountText')?.getList('runs')) + .stripNonDigits() + .nullIfWhitespace ?? + '0'), + (renderer.getList('thumbnails')?[0].getList('thumbnails') ?? const []) + .map((e) => Thumbnail(Uri.parse(e['url']), e['height'], e['width'])) + .toList(), + ); } if (content['channelRenderer'] != null) { var renderer = content.get('channelRenderer')!; diff --git a/lib/src/search/search_client.dart b/lib/src/search/search_client.dart index 683ece9..4743ab3 100644 --- a/lib/src/search/search_client.dart +++ b/lib/src/search/search_client.dart @@ -52,7 +52,7 @@ class SearchClient { @Deprecated( 'Since version 1.9.0 this is the same as [SearchClient.getVideos].') Stream getVideosFromPage(String searchQuery, - {bool onlyVideos = true, + {bool onlyVideos = false, SearchFilter filter = const SearchFilter('')}) async* { SearchPage? page; // ignore: literal_only_boolean_expressions diff --git a/lib/src/search/search_playlist.dart b/lib/src/search/search_playlist.dart index 3b5910f..cb34b3f 100644 --- a/lib/src/search/search_playlist.dart +++ b/lib/src/search/search_playlist.dart @@ -1,5 +1,6 @@ import 'package:freezed_annotation/freezed_annotation.dart'; +import '../common/common.dart'; import '../playlists/playlist_id.dart'; import 'base_search_content.dart'; @@ -19,5 +20,8 @@ class SearchPlaylist with _$SearchPlaylist, BaseSearchContent { String playlistTitle, /// Playlist video count, cannot be greater than 50. - int playlistVideoCount) = _SearchChannel; + int playlistVideoCount, + + /// Video thumbnail + List thumbnails) = _SearchPlaylist; } diff --git a/lib/src/search/search_playlist.freezed.dart b/lib/src/search/search_playlist.freezed.dart index 772ecfe..4972758 100644 --- a/lib/src/search/search_playlist.freezed.dart +++ b/lib/src/search/search_playlist.freezed.dart @@ -17,12 +17,13 @@ final _privateConstructorUsedError = UnsupportedError( class _$SearchPlaylistTearOff { const _$SearchPlaylistTearOff(); - _SearchChannel call( - PlaylistId playlistId, String playlistTitle, int playlistVideoCount) { - return _SearchChannel( + _SearchPlaylist call(PlaylistId playlistId, String playlistTitle, + int playlistVideoCount, List thumbnails) { + return _SearchPlaylist( playlistId, playlistTitle, playlistVideoCount, + thumbnails, ); } } @@ -41,6 +42,9 @@ mixin _$SearchPlaylist { /// Playlist video count, cannot be greater than 50. int get playlistVideoCount => throw _privateConstructorUsedError; + /// Video thumbnail + List get thumbnails => throw _privateConstructorUsedError; + @JsonKey(ignore: true) $SearchPlaylistCopyWith get copyWith => throw _privateConstructorUsedError; @@ -52,7 +56,10 @@ abstract class $SearchPlaylistCopyWith<$Res> { SearchPlaylist value, $Res Function(SearchPlaylist) then) = _$SearchPlaylistCopyWithImpl<$Res>; $Res call( - {PlaylistId playlistId, String playlistTitle, int playlistVideoCount}); + {PlaylistId playlistId, + String playlistTitle, + int playlistVideoCount, + List thumbnails}); $PlaylistIdCopyWith<$Res> get playlistId; } @@ -71,6 +78,7 @@ class _$SearchPlaylistCopyWithImpl<$Res> Object? playlistId = freezed, Object? playlistTitle = freezed, Object? playlistVideoCount = freezed, + Object? thumbnails = freezed, }) { return _then(_value.copyWith( playlistId: playlistId == freezed @@ -85,6 +93,10 @@ class _$SearchPlaylistCopyWithImpl<$Res> ? _value.playlistVideoCount : playlistVideoCount // ignore: cast_nullable_to_non_nullable as int, + thumbnails: thumbnails == freezed + ? _value.thumbnails + : thumbnails // ignore: cast_nullable_to_non_nullable + as List, )); } @@ -97,37 +109,41 @@ class _$SearchPlaylistCopyWithImpl<$Res> } /// @nodoc -abstract class _$SearchChannelCopyWith<$Res> +abstract class _$SearchPlaylistCopyWith<$Res> implements $SearchPlaylistCopyWith<$Res> { - factory _$SearchChannelCopyWith( - _SearchChannel value, $Res Function(_SearchChannel) then) = - __$SearchChannelCopyWithImpl<$Res>; + factory _$SearchPlaylistCopyWith( + _SearchPlaylist value, $Res Function(_SearchPlaylist) then) = + __$SearchPlaylistCopyWithImpl<$Res>; @override $Res call( - {PlaylistId playlistId, String playlistTitle, int playlistVideoCount}); + {PlaylistId playlistId, + String playlistTitle, + int playlistVideoCount, + List thumbnails}); @override $PlaylistIdCopyWith<$Res> get playlistId; } /// @nodoc -class __$SearchChannelCopyWithImpl<$Res> +class __$SearchPlaylistCopyWithImpl<$Res> extends _$SearchPlaylistCopyWithImpl<$Res> - implements _$SearchChannelCopyWith<$Res> { - __$SearchChannelCopyWithImpl( - _SearchChannel _value, $Res Function(_SearchChannel) _then) - : super(_value, (v) => _then(v as _SearchChannel)); + implements _$SearchPlaylistCopyWith<$Res> { + __$SearchPlaylistCopyWithImpl( + _SearchPlaylist _value, $Res Function(_SearchPlaylist) _then) + : super(_value, (v) => _then(v as _SearchPlaylist)); @override - _SearchChannel get _value => super._value as _SearchChannel; + _SearchPlaylist get _value => super._value as _SearchPlaylist; @override $Res call({ Object? playlistId = freezed, Object? playlistTitle = freezed, Object? playlistVideoCount = freezed, + Object? thumbnails = freezed, }) { - return _then(_SearchChannel( + return _then(_SearchPlaylist( playlistId == freezed ? _value.playlistId : playlistId // ignore: cast_nullable_to_non_nullable @@ -140,6 +156,10 @@ class __$SearchChannelCopyWithImpl<$Res> ? _value.playlistVideoCount : playlistVideoCount // ignore: cast_nullable_to_non_nullable as int, + thumbnails == freezed + ? _value.thumbnails + : thumbnails // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -147,9 +167,9 @@ class __$SearchChannelCopyWithImpl<$Res> /// @nodoc @With(BaseSearchContent) -class _$_SearchChannel with BaseSearchContent implements _SearchChannel { - const _$_SearchChannel( - this.playlistId, this.playlistTitle, this.playlistVideoCount); +class _$_SearchPlaylist with BaseSearchContent implements _SearchPlaylist { + const _$_SearchPlaylist(this.playlistId, this.playlistTitle, + this.playlistVideoCount, this.thumbnails); @override @@ -163,16 +183,20 @@ class _$_SearchChannel with BaseSearchContent implements _SearchChannel { /// Playlist video count, cannot be greater than 50. final int playlistVideoCount; + @override + + /// Video thumbnail + final List thumbnails; @override String toString() { - return 'SearchPlaylist(playlistId: $playlistId, playlistTitle: $playlistTitle, playlistVideoCount: $playlistVideoCount)'; + return 'SearchPlaylist(playlistId: $playlistId, playlistTitle: $playlistTitle, playlistVideoCount: $playlistVideoCount, thumbnails: $thumbnails)'; } @override bool operator ==(dynamic other) { return identical(this, other) || - (other is _SearchChannel && + (other is _SearchPlaylist && (identical(other.playlistId, playlistId) || const DeepCollectionEquality() .equals(other.playlistId, playlistId)) && @@ -181,7 +205,10 @@ class _$_SearchChannel with BaseSearchContent implements _SearchChannel { .equals(other.playlistTitle, playlistTitle)) && (identical(other.playlistVideoCount, playlistVideoCount) || const DeepCollectionEquality() - .equals(other.playlistVideoCount, playlistVideoCount))); + .equals(other.playlistVideoCount, playlistVideoCount)) && + (identical(other.thumbnails, thumbnails) || + const DeepCollectionEquality() + .equals(other.thumbnails, thumbnails))); } @override @@ -189,18 +216,18 @@ class _$_SearchChannel with BaseSearchContent implements _SearchChannel { runtimeType.hashCode ^ const DeepCollectionEquality().hash(playlistId) ^ const DeepCollectionEquality().hash(playlistTitle) ^ - const DeepCollectionEquality().hash(playlistVideoCount); + const DeepCollectionEquality().hash(playlistVideoCount) ^ + const DeepCollectionEquality().hash(thumbnails); @JsonKey(ignore: true) @override - _$SearchChannelCopyWith<_SearchChannel> get copyWith => - __$SearchChannelCopyWithImpl<_SearchChannel>(this, _$identity); + _$SearchPlaylistCopyWith<_SearchPlaylist> get copyWith => + __$SearchPlaylistCopyWithImpl<_SearchPlaylist>(this, _$identity); } -abstract class _SearchChannel implements SearchPlaylist, BaseSearchContent { - const factory _SearchChannel( - PlaylistId playlistId, String playlistTitle, int playlistVideoCount) = - _$_SearchChannel; +abstract class _SearchPlaylist implements SearchPlaylist, BaseSearchContent { + const factory _SearchPlaylist(PlaylistId playlistId, String playlistTitle, + int playlistVideoCount, List thumbnails) = _$_SearchPlaylist; @override @@ -215,7 +242,11 @@ abstract class _SearchChannel implements SearchPlaylist, BaseSearchContent { /// Playlist video count, cannot be greater than 50. int get playlistVideoCount => throw _privateConstructorUsedError; @override + + /// Video thumbnail + List get thumbnails => throw _privateConstructorUsedError; + @override @JsonKey(ignore: true) - _$SearchChannelCopyWith<_SearchChannel> get copyWith => + _$SearchPlaylistCopyWith<_SearchPlaylist> get copyWith => throw _privateConstructorUsedError; }