Merge pull request #176 from mitchpk/master
Improve playlist search parsing
This commit is contained in:
commit
238ce1bc6f
|
@ -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<String>('playlistId')!),
|
||||
renderer.get('title')!.getT<String>('simpleText')!,
|
||||
int.parse(_parseRuns(renderer.get('videoCountText')?.getList('runs'))
|
||||
.stripNonDigits()
|
||||
.nullIfWhitespace ??
|
||||
'0'));
|
||||
PlaylistId(renderer.getT<String>('playlistId')!),
|
||||
renderer.get('title')!.getT<String>('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')!;
|
||||
|
|
|
@ -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<Thumbnail> thumbnails) = _SearchPlaylist;
|
||||
}
|
||||
|
|
|
@ -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<Thumbnail> 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<Thumbnail> get thumbnails => throw _privateConstructorUsedError;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
$SearchPlaylistCopyWith<SearchPlaylist> 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<Thumbnail> 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<Thumbnail>,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -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<Thumbnail> 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<Thumbnail>,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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<Thumbnail> 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<Thumbnail> 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<Thumbnail> get thumbnails => throw _privateConstructorUsedError;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$SearchChannelCopyWith<_SearchChannel> get copyWith =>
|
||||
_$SearchPlaylistCopyWith<_SearchPlaylist> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue