From 4562de0dedd0d5038c6310ef4abd0b05828d7a8f Mon Sep 17 00:00:00 2001 From: Mattia Date: Mon, 28 Jun 2021 11:54:17 +0200 Subject: [PATCH] Version v1.9.7 Fix #135 --- CHANGELOG.md | 5 +++- .../responses/channel_upload_page.dart | 28 ++++++++++++++----- lib/src/videos/video.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c244abd..0784c89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ +## 1.9.7 +- Fix issue #135 (Cannot use getUploadsFromPage on a channel with no uploads). + ## 1.9.6 - Fix comment client. - Fix issue #130 (ClosedCaptions) -- Fix + ## 1.9.5 - Temporary for issue #130 diff --git a/lib/src/reverse_engineering/responses/channel_upload_page.dart b/lib/src/reverse_engineering/responses/channel_upload_page.dart index 721249c..e27b6bd 100644 --- a/lib/src/reverse_engineering/responses/channel_upload_page.dart +++ b/lib/src/reverse_engineering/responses/channel_upload_page.dart @@ -93,13 +93,20 @@ class _InitialData { late final String token = continuationContext?.getT('token') ?? ''; - late final List uploads = - getContentContext().map(_parseContent).whereNotNull().toList(); + late final List uploads = _getUploads(); + + List _getUploads() { + final content = getContentContext(); + if (content.isEmpty) { + return const []; + } + return content.map(_parseContent).whereNotNull().toList(); + } List> getContentContext() { List>? context; if (root.containsKey('contents')) { - context = root + final render = root .get('contents') ?.get('twoColumnBrowseResultsRenderer') ?.getList('tabs') @@ -112,10 +119,17 @@ class _InitialData { ?.firstOrNull ?.get('itemSectionRenderer') ?.getList('contents') - ?.firstOrNull - ?.get('gridRenderer') - ?.getList('items') - ?.cast>(); + ?.firstOrNull; + + if (render?.containsKey('gridRenderer') ?? false) { + context = render + ?.get('gridRenderer') + ?.getList('items') + ?.cast>(); + } else if (render?.containsKey('messageRenderer') ?? false) { + // Workaround for no-videos. + context = const []; + } } if (context == null && root.containsKey('onResponseReceivedActions')) { context = root diff --git a/lib/src/videos/video.dart b/lib/src/videos/video.dart index a9bdb7d..28ee396 100644 --- a/lib/src/videos/video.dart +++ b/lib/src/videos/video.dart @@ -73,7 +73,7 @@ class Video with EquatableMixin { this.engagement, this.isLive, // ignore: avoid_positional_boolean_parameters [this.watchPage]) - : keywords = UnmodifiableListView(keywords ?? []); + : keywords = UnmodifiableListView(keywords ?? const []); @override String toString() => 'Video ($title)'; diff --git a/pubspec.yaml b/pubspec.yaml index e97b472..f10886f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: youtube_explode_dart description: A port in dart of the youtube explode library. Supports several API functions without the need of Youtube API Key. -version: 1.9.6 +version: 1.9.7 homepage: https://github.com/Hexer10/youtube_explode_dart