From 42617b5ac0ac56116bc65573cc062ff13b31af17 Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 11 Mar 2021 14:20:10 +0100 Subject: [PATCH] Version 1.9.0-nullsafety.2 #107 --- CHANGELOG.md | 9 + analysis_options.yaml | 72 +- example/example.dart | 9 +- example/video_download.dart | 4 +- lib/src/channels/channel_client.dart | 12 +- lib/src/channels/channel_id.dart | 2 +- lib/src/common/engagement.dart | 20 - .../exceptions/fatal_failure_exception.dart | 3 +- .../request_limit_exceeded_exception.dart | 3 +- .../transient_failure_exception.dart | 3 +- .../video_requires_purchase_exception.dart | 10 +- .../video_unavailable_exception.dart | 3 +- .../video_unplayable_exception.dart | 4 +- lib/src/extensions/helpers_extension.dart | 24 +- lib/src/playlists/playlist_client.dart | 10 +- .../responses/channel_about_page.dart | 96 +- .../responses/channel_upload_page.dart | 165 +- .../closed_caption_track_response.dart | 49 +- .../responses/dash_manifest.dart | 44 +- .../responses/embed_page.dart | 31 +- .../generated/channel_about_page_id.g.dart | 5718 -------- .../generated/channel_upload_page_id.g.dart | 6587 ---------- .../generated/player_response.g.dart | 4492 ------- .../generated/player_response_json.g.dart | 239 - .../generated/playlist_page_id.g.dart | 10846 ---------------- .../generated/playlist_response.g.dart | 205 - .../responses/generated/readme.md | 2 - .../responses/generated/search_page_id.g.dart | 6438 --------- .../responses/generated/watch_page_id.g.dart | 7661 ----------- .../responses/player_response.dart | 245 +- .../responses/player_source.dart | 90 +- .../responses/playlist_page.dart | 115 +- .../responses/search_page.dart | 248 +- .../responses/stream_info_provider.dart | 44 +- .../responses/video_info_response.dart | 120 +- .../responses/watch_page.dart | 177 +- .../youtube_http_client.dart | 4 + lib/src/search/search_client.dart | 11 +- lib/src/search/search_list.dart | 9 +- lib/src/search/search_query.dart | 2 +- lib/src/search/search_video.dart | 2 +- .../closed_captions/closed_caption.dart | 5 +- .../closed_captions/closed_caption.g.dart | 17 +- .../closed_caption_client.dart | 8 +- .../closed_caption_manifest.dart | 2 +- .../closed_caption_part.g.dart | 6 +- .../closed_captions/closed_caption_track.dart | 5 +- .../closed_caption_track.g.dart | 4 +- .../closed_caption_track_info.dart | 5 +- .../closed_caption_track_info.g.dart | 13 +- lib/src/videos/comments/comment.dart | 4 +- lib/src/videos/comments/comments_client.dart | 24 +- lib/src/videos/streams/streams_client.dart | 46 +- lib/src/videos/video.dart | 34 +- lib/src/videos/video_client.dart | 2 +- lib/src/youtube_explode_base.dart | 23 +- pubspec.yaml | 21 +- test/channel_about_test.dart | 6 +- test/channel_id_test.dart | 8 +- test/channel_test.dart | 22 +- test/closed_caption_test.dart | 45 +- test/comments_client_test.dart | 8 +- test/playlist_id_test.dart | 8 +- test/playlist_test.dart | 16 +- test/search_test.dart | 17 +- test/streams_test.dart | 26 +- test/user_name_test.dart | 8 +- test/video_id_test.dart | 8 +- test/video_test.dart | 20 +- tool/grind.dart | 6 +- 70 files changed, 961 insertions(+), 43284 deletions(-) delete mode 100644 lib/src/reverse_engineering/responses/generated/channel_about_page_id.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/channel_upload_page_id.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/player_response.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/player_response_json.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/playlist_page_id.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/playlist_response.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/readme.md delete mode 100644 lib/src/reverse_engineering/responses/generated/search_page_id.g.dart delete mode 100644 lib/src/reverse_engineering/responses/generated/watch_page_id.g.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 10de743..3ae9a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.9.0 +- Support nnbd (dart 1.12) + +## 1.8.0 +- Fixed playlist client. +- Fixed search client. +- `search.getVideos` now returns a `Video` instance. +- Implemented `SearchList`. + ## 1.8.0-beta.4 - Removed debug message diff --git a/analysis_options.yaml b/analysis_options.yaml index 00f2413..bfe6588 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,69 +1,13 @@ -include: package:effective_dart/analysis_options.yaml +include: package:lint/analysis_options.yaml analyzer: - exclude: #most likely not all of these are needed, but as it is now it works. - - "**/*.g.dart" - - /**/*.g.dart - - \**\*.g.dart - - "*.g.dart" - - "**.g.dart" - - example\** - - lib\src\reverse_engineering\responses\generated\** + strong-mode: + implicit-casts: true + implicit-dynamic: true linter: rules: - - valid_regexps - - prefer_const_constructors - - prefer_const_declarations - - prefer_const_literals_to_create_immutables - - prefer_constructors_over_static_methods - - prefer_contains - - annotate_overrides - - await_only_futures - - unawaited_futures - - avoid_empty_else - - avoid_returning_null_for_future - - avoid_types_as_parameter_names - - control_flow_in_finally - - empty_statements - - invariant_booleans - - iterable_contains_unrelated_type - - list_remove_unrelated_type - - literal_only_boolean_expressions - - no_adjacent_strings_in_list - - no_duplicate_case_values - - prefer_void_to_null - - test_types_in_equals - - throw_in_finally - - unnecessary_statements - - unrelated_type_equality_checks - - always_declare_return_types - - always_put_control_body_on_new_line - - avoid_returning_null_for_void - - avoid_setters_without_getters - - avoid_shadowing_type_parameters - - avoid_unnecessary_containers - - avoid_void_async - - empty_catches - - null_closures - - prefer_conditional_assignment - - prefer_if_null_operators - - prefer_is_empty - - prefer_is_not_empty - - prefer_is_not_operator - - prefer_null_aware_operators - - recursive_getters - - unnecessary_await_in_return - - unnecessary_null_aware_assignments - - unnecessary_null_in_if_null_operators - - unnecessary_overrides - - unnecessary_parenthesis - - unnecessary_raw_strings - - unnecessary_string_escapes - - unnecessary_string_interpolations - - use_string_buffers - - void_checks - - package_names - - prefer_single_quotes - - use_function_type_syntax_for_parameters - + prefer_final_locals: false + parameter_assignments: false + no_runtimetype_tostring: false + avoid_escaping_inner_quotes: false diff --git a/example/example.dart b/example/example.dart index 8b509c5..646a836 100644 --- a/example/example.dart +++ b/example/example.dart @@ -1,15 +1,14 @@ +// ignore_for_file: avoid_print import 'package:youtube_explode_dart/youtube_explode_dart.dart'; Future main() async { - var yt = YoutubeExplode(); + final yt = YoutubeExplode(); - var manifest = await yt.videos.closedCaptions - .getManifest('Pxgvgh9IFqA', autoGenerated: true); + var manifest = await yt.videos.closedCaptions.getManifest('Pxgvgh9IFqA'); print(manifest.tracks); print('\n\n---------------------\n\n'); - manifest = await yt.videos.closedCaptions - .getManifest('Pxgvgh9IFqA', autoGenerated: false); + manifest = await yt.videos.closedCaptions.getManifest('Pxgvgh9IFqA'); print(manifest.tracks); yt.close(); } diff --git a/example/video_download.dart b/example/video_download.dart index 3d1277c..ee1a91a 100644 --- a/example/video_download.dart +++ b/example/video_download.dart @@ -12,7 +12,7 @@ final yt = YoutubeExplode(); Future main() async { stdout.writeln('Type the video id or url: '); - var url = stdin.readLineSync().trim(); + var url = stdin.readLineSync()!.trim(); // Save the video to the download directory. Directory('downloads').createSync(); @@ -66,7 +66,7 @@ Future download(String id) async { // Listen for data received. var progressBar = ProgressBar(); - await for (var data in audioStream) { + await for (final data in audioStream) { // Keep track of the current downloaded data. count += data.length; diff --git a/lib/src/channels/channel_client.dart b/lib/src/channels/channel_client.dart index 01931ad..d090135 100644 --- a/lib/src/channels/channel_client.dart +++ b/lib/src/channels/channel_client.dart @@ -49,9 +49,6 @@ class ChannelClient { Future getAboutPage(dynamic id) async { id = ChannelId.fromString(id); - var channelAboutPage = await ChannelAboutPage.get(_httpClient, id.value); - var iData = channelAboutPage.initialData; - assert(iData != null); return ChannelAbout( id.description, id.viewCount, @@ -74,7 +71,6 @@ class ChannelClient { var channelAboutPage = await ChannelAboutPage.getByUsername(_httpClient, username.value); var id = channelAboutPage.initialData; - assert(id != null); return ChannelAbout( id.description, id.viewCount, @@ -82,7 +78,7 @@ class ChannelClient { id.title, [ for (var e in id.avatar) - Thumbnail(Uri.parse(e.url), e.height, e.width) + Thumbnail(Uri.parse(e['url']), e['height'], e['width']) ], id.country, id.channelLinks); @@ -118,13 +114,13 @@ class ChannelClient { Stream getUploadsFromPage(dynamic channelId, [VideoSorting videoSorting = VideoSorting.newest]) async* { channelId = ChannelId.fromString(channelId); - var page = await ChannelUploadPage.get( - _httpClient, channelId.value, videoSorting.code); + ChannelUploadPage? page = await ChannelUploadPage.get( + _httpClient, (channelId as ChannelId).value, videoSorting.code); yield* Stream.fromIterable(page.initialData.uploads); // ignore: literal_only_boolean_expressions while (true) { - page = await page.nextPage(_httpClient); + page = await page!.nextPage(_httpClient); if (page == null) { return; } diff --git a/lib/src/channels/channel_id.dart b/lib/src/channels/channel_id.dart index fb8e02e..933a069 100644 --- a/lib/src/channels/channel_id.dart +++ b/lib/src/channels/channel_id.dart @@ -9,7 +9,7 @@ class ChannelId with EquatableMixin { /// Initializes an instance of [ChannelId] ChannelId(String value) : value = parseChannelId(value) ?? '' { - if (value.isEmpty) { + if (this.value.isEmpty) { throw ArgumentError.value(value); } } diff --git a/lib/src/common/engagement.dart b/lib/src/common/engagement.dart index 45d9060..6e12f98 100644 --- a/lib/src/common/engagement.dart +++ b/lib/src/common/engagement.dart @@ -33,23 +33,3 @@ class Engagement extends Equatable { @override List get props => [viewCount, likeCount, dislikeCount]; } - -/// User activity statistics. -/// No null types -class SafeEngagement extends Engagement { - @override - final int viewCount; - - @override - final int likeCount; - - @override - final int dislikeCount; - - /// Initializes an instance of [Engagement] - const SafeEngagement(this.viewCount, this.likeCount, this.dislikeCount) - : super(viewCount, likeCount, dislikeCount); - - @override - List get props => [viewCount, likeCount, dislikeCount]; -} diff --git a/lib/src/exceptions/fatal_failure_exception.dart b/lib/src/exceptions/fatal_failure_exception.dart index 273b1e1..82e3742 100644 --- a/lib/src/exceptions/fatal_failure_exception.dart +++ b/lib/src/exceptions/fatal_failure_exception.dart @@ -22,5 +22,6 @@ Response: (${response.statusCode}) '''; @override - String toString() => '$runtimeType: $message'; + String toString() => + '$runtimeType: $message'; // ignore: no_runtimetype_tostring } diff --git a/lib/src/exceptions/request_limit_exceeded_exception.dart b/lib/src/exceptions/request_limit_exceeded_exception.dart index 46b8129..f3bcaa5 100644 --- a/lib/src/exceptions/request_limit_exceeded_exception.dart +++ b/lib/src/exceptions/request_limit_exceeded_exception.dart @@ -23,5 +23,6 @@ Response: $response '''; @override - String toString() => '$runtimeType: $message'; + String toString() => + '$runtimeType: $message'; // ignore: no_runtimetype_tostring } diff --git a/lib/src/exceptions/transient_failure_exception.dart b/lib/src/exceptions/transient_failure_exception.dart index 9551341..1cc8356 100644 --- a/lib/src/exceptions/transient_failure_exception.dart +++ b/lib/src/exceptions/transient_failure_exception.dart @@ -22,5 +22,6 @@ Response: $response '''; @override - String toString() => '$runtimeType: $message'; + String toString() => + '$runtimeType: $message'; // ignore: no_runtimetype_tostring } diff --git a/lib/src/exceptions/video_requires_purchase_exception.dart b/lib/src/exceptions/video_requires_purchase_exception.dart index c0760b4..edecc28 100644 --- a/lib/src/exceptions/video_requires_purchase_exception.dart +++ b/lib/src/exceptions/video_requires_purchase_exception.dart @@ -12,10 +12,12 @@ class VideoRequiresPurchaseException implements VideoUnplayableException { /// Initializes an instance of [VideoRequiresPurchaseException]. VideoRequiresPurchaseException.preview(VideoId videoId, this.previewVideoId) - : message = 'Video `$videoId` is unplayable because it requires purchase.' - 'Streams are not available for this video.' - 'There is a preview video available: `$previewVideoId`.'; + : message = + 'Video `$videoId` is unplayable because it requires purchase.\n' + 'Streams are not available for this video.\n' + 'There is a preview video available: `$previewVideoId`.'; @override - String toString() => '$runtimeType: $message'; + String toString() => + '$runtimeType: $message'; // ignore: no_runtimetype_tostring } diff --git a/lib/src/exceptions/video_unavailable_exception.dart b/lib/src/exceptions/video_unavailable_exception.dart index 5fd6157..bea276c 100644 --- a/lib/src/exceptions/video_unavailable_exception.dart +++ b/lib/src/exceptions/video_unavailable_exception.dart @@ -22,5 +22,6 @@ class VideoUnavailableException implements VideoUnplayableException { 'Please report this issue on GitHub in that case.'; @override - String toString() => '$runtimeType: $message'; + String toString() => + '$runtimeType: $message'; // ignore: no_runtimetype_tostring } diff --git a/lib/src/exceptions/video_unplayable_exception.dart b/lib/src/exceptions/video_unplayable_exception.dart index 74f26ef..c8b0174 100644 --- a/lib/src/exceptions/video_unplayable_exception.dart +++ b/lib/src/exceptions/video_unplayable_exception.dart @@ -30,5 +30,7 @@ class VideoUnplayableException implements YoutubeExplodeException { 'Live stream manifest is not available for this video'; @override - String toString() => '$runtimeType: $message'; + // ignore: + String toString() => + '$runtimeType: $message'; // ignore: no_runtimetype_tostring } diff --git a/lib/src/extensions/helpers_extension.dart b/lib/src/extensions/helpers_extension.dart index a3c4b37..c233429 100644 --- a/lib/src/extensions/helpers_extension.dart +++ b/lib/src/extensions/helpers_extension.dart @@ -42,6 +42,8 @@ extension StringUtility on String { } return buffer.toString(); } + + DateTime parseDateTime() => DateTime.parse(this); } /// Utility for Strings. @@ -66,7 +68,7 @@ extension StringUtility2 on String? { extension ListDecipher on Iterable { /// Apply every CipherOperation on the [signature] String decipher(String signature) { - for (var operation in this) { + for (final operation in this) { signature = operation.decipher(signature); } @@ -76,14 +78,6 @@ extension ListDecipher on Iterable { /// List Utility. extension ListUtil on Iterable { - /// Returns the first element of a list or null if empty. - E? get firstOrNull { - if (length == 0) { - return null; - } - return first; - } - /// Same as [elementAt] but if the index is higher than the length returns /// null E? elementAtSafe(int index) { @@ -92,16 +86,6 @@ extension ListUtil on Iterable { } return elementAt(index); } - - /// Same as [firstWhere] but returns null if no found - E? firstWhereNull(bool Function(E element) test) { - for (final element in this) { - if (test(element)) { - return element; - } - } - return null; - } } /// Uri utility @@ -180,5 +164,5 @@ extension UriUtils on Uri { /// Parse properties with `text` method. extension RunsParser on List { /// - String parseRuns() => map((e) => e['text']).join() ?? ''; + String parseRuns() => map((e) => e['text']).join(); } diff --git a/lib/src/playlists/playlist_client.dart b/lib/src/playlists/playlist_client.dart index 9d11d37..130efdd 100644 --- a/lib/src/playlists/playlist_client.dart +++ b/lib/src/playlists/playlist_client.dart @@ -22,9 +22,9 @@ class PlaylistClient { var response = await PlaylistPage.get(_httpClient, id.value); return Playlist( id, - response.initialData.title, - response.initialData.author, - response.initialData.description, + response.initialData.title ?? '', + response.initialData.author ?? '', + response.initialData.description ?? '', ThumbnailSet(id.value), Engagement(response.initialData.viewCount ?? 0, null, null)); } @@ -33,14 +33,14 @@ class PlaylistClient { Stream