Merge pull request #176 from mitchpk/master

Improve playlist search parsing
This commit is contained in:
Mattia 2021-10-18 08:52:37 +02:00 committed by GitHub
commit 238ce1bc6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 39 deletions

View File

@ -191,16 +191,22 @@ class _InitialData extends InitialData {
renderer['ownerText']['runs'][0]['navigationEndpoint'] renderer['ownerText']['runs'][0]['navigationEndpoint']
['browseEndpoint']['browseId']); ['browseEndpoint']['browseId']);
} }
if (content['radioRenderer'] != null) { if (content['radioRenderer'] != null ||
var renderer = content.get('radioRenderer')!; content['playlistRenderer'] != null) {
var renderer =
(content.get('radioRenderer') ?? content.get('playlistRenderer'))!;
return SearchPlaylist( return SearchPlaylist(
PlaylistId(renderer.getT<String>('playlistId')!), PlaylistId(renderer.getT<String>('playlistId')!),
renderer.get('title')!.getT<String>('simpleText')!, renderer.get('title')!.getT<String>('simpleText')!,
int.parse(_parseRuns(renderer.get('videoCountText')?.getList('runs')) int.parse(_parseRuns(renderer.get('videoCountText')?.getList('runs'))
.stripNonDigits() .stripNonDigits()
.nullIfWhitespace ?? .nullIfWhitespace ??
'0')); '0'),
(renderer.getList('thumbnails')?[0].getList('thumbnails') ?? const [])
.map((e) => Thumbnail(Uri.parse(e['url']), e['height'], e['width']))
.toList(),
);
} }
if (content['channelRenderer'] != null) { if (content['channelRenderer'] != null) {
var renderer = content.get('channelRenderer')!; var renderer = content.get('channelRenderer')!;

View File

@ -1,5 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import '../common/common.dart';
import '../playlists/playlist_id.dart'; import '../playlists/playlist_id.dart';
import 'base_search_content.dart'; import 'base_search_content.dart';
@ -19,5 +20,8 @@ class SearchPlaylist with _$SearchPlaylist, BaseSearchContent {
String playlistTitle, String playlistTitle,
/// Playlist video count, cannot be greater than 50. /// Playlist video count, cannot be greater than 50.
int playlistVideoCount) = _SearchChannel; int playlistVideoCount,
/// Video thumbnail
List<Thumbnail> thumbnails) = _SearchPlaylist;
} }

View File

@ -17,12 +17,13 @@ final _privateConstructorUsedError = UnsupportedError(
class _$SearchPlaylistTearOff { class _$SearchPlaylistTearOff {
const _$SearchPlaylistTearOff(); const _$SearchPlaylistTearOff();
_SearchChannel call( _SearchPlaylist call(PlaylistId playlistId, String playlistTitle,
PlaylistId playlistId, String playlistTitle, int playlistVideoCount) { int playlistVideoCount, List<Thumbnail> thumbnails) {
return _SearchChannel( return _SearchPlaylist(
playlistId, playlistId,
playlistTitle, playlistTitle,
playlistVideoCount, playlistVideoCount,
thumbnails,
); );
} }
} }
@ -41,6 +42,9 @@ mixin _$SearchPlaylist {
/// Playlist video count, cannot be greater than 50. /// Playlist video count, cannot be greater than 50.
int get playlistVideoCount => throw _privateConstructorUsedError; int get playlistVideoCount => throw _privateConstructorUsedError;
/// Video thumbnail
List<Thumbnail> get thumbnails => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
$SearchPlaylistCopyWith<SearchPlaylist> get copyWith => $SearchPlaylistCopyWith<SearchPlaylist> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -52,7 +56,10 @@ abstract class $SearchPlaylistCopyWith<$Res> {
SearchPlaylist value, $Res Function(SearchPlaylist) then) = SearchPlaylist value, $Res Function(SearchPlaylist) then) =
_$SearchPlaylistCopyWithImpl<$Res>; _$SearchPlaylistCopyWithImpl<$Res>;
$Res call( $Res call(
{PlaylistId playlistId, String playlistTitle, int playlistVideoCount}); {PlaylistId playlistId,
String playlistTitle,
int playlistVideoCount,
List<Thumbnail> thumbnails});
$PlaylistIdCopyWith<$Res> get playlistId; $PlaylistIdCopyWith<$Res> get playlistId;
} }
@ -71,6 +78,7 @@ class _$SearchPlaylistCopyWithImpl<$Res>
Object? playlistId = freezed, Object? playlistId = freezed,
Object? playlistTitle = freezed, Object? playlistTitle = freezed,
Object? playlistVideoCount = freezed, Object? playlistVideoCount = freezed,
Object? thumbnails = freezed,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
playlistId: playlistId == freezed playlistId: playlistId == freezed
@ -85,6 +93,10 @@ class _$SearchPlaylistCopyWithImpl<$Res>
? _value.playlistVideoCount ? _value.playlistVideoCount
: playlistVideoCount // ignore: cast_nullable_to_non_nullable : playlistVideoCount // ignore: cast_nullable_to_non_nullable
as int, as int,
thumbnails: thumbnails == freezed
? _value.thumbnails
: thumbnails // ignore: cast_nullable_to_non_nullable
as List<Thumbnail>,
)); ));
} }
@ -97,37 +109,41 @@ class _$SearchPlaylistCopyWithImpl<$Res>
} }
/// @nodoc /// @nodoc
abstract class _$SearchChannelCopyWith<$Res> abstract class _$SearchPlaylistCopyWith<$Res>
implements $SearchPlaylistCopyWith<$Res> { implements $SearchPlaylistCopyWith<$Res> {
factory _$SearchChannelCopyWith( factory _$SearchPlaylistCopyWith(
_SearchChannel value, $Res Function(_SearchChannel) then) = _SearchPlaylist value, $Res Function(_SearchPlaylist) then) =
__$SearchChannelCopyWithImpl<$Res>; __$SearchPlaylistCopyWithImpl<$Res>;
@override @override
$Res call( $Res call(
{PlaylistId playlistId, String playlistTitle, int playlistVideoCount}); {PlaylistId playlistId,
String playlistTitle,
int playlistVideoCount,
List<Thumbnail> thumbnails});
@override @override
$PlaylistIdCopyWith<$Res> get playlistId; $PlaylistIdCopyWith<$Res> get playlistId;
} }
/// @nodoc /// @nodoc
class __$SearchChannelCopyWithImpl<$Res> class __$SearchPlaylistCopyWithImpl<$Res>
extends _$SearchPlaylistCopyWithImpl<$Res> extends _$SearchPlaylistCopyWithImpl<$Res>
implements _$SearchChannelCopyWith<$Res> { implements _$SearchPlaylistCopyWith<$Res> {
__$SearchChannelCopyWithImpl( __$SearchPlaylistCopyWithImpl(
_SearchChannel _value, $Res Function(_SearchChannel) _then) _SearchPlaylist _value, $Res Function(_SearchPlaylist) _then)
: super(_value, (v) => _then(v as _SearchChannel)); : super(_value, (v) => _then(v as _SearchPlaylist));
@override @override
_SearchChannel get _value => super._value as _SearchChannel; _SearchPlaylist get _value => super._value as _SearchPlaylist;
@override @override
$Res call({ $Res call({
Object? playlistId = freezed, Object? playlistId = freezed,
Object? playlistTitle = freezed, Object? playlistTitle = freezed,
Object? playlistVideoCount = freezed, Object? playlistVideoCount = freezed,
Object? thumbnails = freezed,
}) { }) {
return _then(_SearchChannel( return _then(_SearchPlaylist(
playlistId == freezed playlistId == freezed
? _value.playlistId ? _value.playlistId
: playlistId // ignore: cast_nullable_to_non_nullable : playlistId // ignore: cast_nullable_to_non_nullable
@ -140,6 +156,10 @@ class __$SearchChannelCopyWithImpl<$Res>
? _value.playlistVideoCount ? _value.playlistVideoCount
: playlistVideoCount // ignore: cast_nullable_to_non_nullable : playlistVideoCount // ignore: cast_nullable_to_non_nullable
as int, as int,
thumbnails == freezed
? _value.thumbnails
: thumbnails // ignore: cast_nullable_to_non_nullable
as List<Thumbnail>,
)); ));
} }
} }
@ -147,9 +167,9 @@ class __$SearchChannelCopyWithImpl<$Res>
/// @nodoc /// @nodoc
@With(BaseSearchContent) @With(BaseSearchContent)
class _$_SearchChannel with BaseSearchContent implements _SearchChannel { class _$_SearchPlaylist with BaseSearchContent implements _SearchPlaylist {
const _$_SearchChannel( const _$_SearchPlaylist(this.playlistId, this.playlistTitle,
this.playlistId, this.playlistTitle, this.playlistVideoCount); this.playlistVideoCount, this.thumbnails);
@override @override
@ -163,16 +183,20 @@ class _$_SearchChannel with BaseSearchContent implements _SearchChannel {
/// Playlist video count, cannot be greater than 50. /// Playlist video count, cannot be greater than 50.
final int playlistVideoCount; final int playlistVideoCount;
@override
/// Video thumbnail
final List<Thumbnail> thumbnails;
@override @override
String toString() { String toString() {
return 'SearchPlaylist(playlistId: $playlistId, playlistTitle: $playlistTitle, playlistVideoCount: $playlistVideoCount)'; return 'SearchPlaylist(playlistId: $playlistId, playlistTitle: $playlistTitle, playlistVideoCount: $playlistVideoCount, thumbnails: $thumbnails)';
} }
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
return identical(this, other) || return identical(this, other) ||
(other is _SearchChannel && (other is _SearchPlaylist &&
(identical(other.playlistId, playlistId) || (identical(other.playlistId, playlistId) ||
const DeepCollectionEquality() const DeepCollectionEquality()
.equals(other.playlistId, playlistId)) && .equals(other.playlistId, playlistId)) &&
@ -181,7 +205,10 @@ class _$_SearchChannel with BaseSearchContent implements _SearchChannel {
.equals(other.playlistTitle, playlistTitle)) && .equals(other.playlistTitle, playlistTitle)) &&
(identical(other.playlistVideoCount, playlistVideoCount) || (identical(other.playlistVideoCount, playlistVideoCount) ||
const DeepCollectionEquality() const DeepCollectionEquality()
.equals(other.playlistVideoCount, playlistVideoCount))); .equals(other.playlistVideoCount, playlistVideoCount)) &&
(identical(other.thumbnails, thumbnails) ||
const DeepCollectionEquality()
.equals(other.thumbnails, thumbnails)));
} }
@override @override
@ -189,18 +216,18 @@ class _$_SearchChannel with BaseSearchContent implements _SearchChannel {
runtimeType.hashCode ^ runtimeType.hashCode ^
const DeepCollectionEquality().hash(playlistId) ^ const DeepCollectionEquality().hash(playlistId) ^
const DeepCollectionEquality().hash(playlistTitle) ^ const DeepCollectionEquality().hash(playlistTitle) ^
const DeepCollectionEquality().hash(playlistVideoCount); const DeepCollectionEquality().hash(playlistVideoCount) ^
const DeepCollectionEquality().hash(thumbnails);
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
_$SearchChannelCopyWith<_SearchChannel> get copyWith => _$SearchPlaylistCopyWith<_SearchPlaylist> get copyWith =>
__$SearchChannelCopyWithImpl<_SearchChannel>(this, _$identity); __$SearchPlaylistCopyWithImpl<_SearchPlaylist>(this, _$identity);
} }
abstract class _SearchChannel implements SearchPlaylist, BaseSearchContent { abstract class _SearchPlaylist implements SearchPlaylist, BaseSearchContent {
const factory _SearchChannel( const factory _SearchPlaylist(PlaylistId playlistId, String playlistTitle,
PlaylistId playlistId, String playlistTitle, int playlistVideoCount) = int playlistVideoCount, List<Thumbnail> thumbnails) = _$_SearchPlaylist;
_$_SearchChannel;
@override @override
@ -215,7 +242,11 @@ abstract class _SearchChannel implements SearchPlaylist, BaseSearchContent {
/// Playlist video count, cannot be greater than 50. /// Playlist video count, cannot be greater than 50.
int get playlistVideoCount => throw _privateConstructorUsedError; int get playlistVideoCount => throw _privateConstructorUsedError;
@override @override
/// Video thumbnail
List<Thumbnail> get thumbnails => throw _privateConstructorUsedError;
@override
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$SearchChannelCopyWith<_SearchChannel> get copyWith => _$SearchPlaylistCopyWith<_SearchPlaylist> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
} }