From 4f9b38d7d2d1a8dce209e83f9b0b96ebdd33a287 Mon Sep 17 00:00:00 2001 From: Mattia Date: Fri, 2 Jul 2021 00:48:10 +0200 Subject: [PATCH] Version v1.9.8 Fix #131 --- CHANGELOG.md | 3 +++ lib/src/extensions/helpers_extension.dart | 7 ++++++ lib/src/videos/video.dart | 1 - lib/src/videos/video_client.dart | 13 +++++++++-- pubspec.yaml | 2 +- test/video_test.dart | 27 +++++++++++++++++------ 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0784c89..d37d9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.9.8 +- Fix issue #131 (Cannot get publishDate or uploadDate) + ## 1.9.7 - Fix issue #135 (Cannot use getUploadsFromPage on a channel with no uploads). diff --git a/lib/src/extensions/helpers_extension.dart b/lib/src/extensions/helpers_extension.dart index 7ad2543..f399a27 100644 --- a/lib/src/extensions/helpers_extension.dart +++ b/lib/src/extensions/helpers_extension.dart @@ -132,6 +132,13 @@ extension StringUtility2 on String? { return DateTime.now().subtract(time); } + + DateTime? tryParseDateTime() { + if (this == null) { + return null; + } + return DateTime.parse(this!); + } } /// List decipher utility. diff --git a/lib/src/videos/video.dart b/lib/src/videos/video.dart index 28ee396..bce95a5 100644 --- a/lib/src/videos/video.dart +++ b/lib/src/videos/video.dart @@ -52,7 +52,6 @@ class Video with EquatableMixin { /// Used internally. /// Shouldn't be used in the code. - /// TODO: Deprecate this method final WatchPage? watchPage; /// Returns true if the watch page is available for this video. diff --git a/lib/src/videos/video_client.dart b/lib/src/videos/video_client.dart index 3bf9d74..3b308b5 100644 --- a/lib/src/videos/video_client.dart +++ b/lib/src/videos/video_client.dart @@ -1,5 +1,6 @@ import '../channels/channel_id.dart'; import '../common/common.dart'; +import '../extensions/helpers_extension.dart'; import '../reverse_engineering/responses/responses.dart'; import '../reverse_engineering/youtube_http_client.dart'; import 'closed_captions/closed_caption_client.dart'; @@ -37,8 +38,16 @@ class VideoClient { playerResponse.videoTitle, playerResponse.videoAuthor, ChannelId(playerResponse.videoChannelId), - playerResponse.videoUploadDate, - playerResponse.videoPublishDate, + playerResponse.videoUploadDate ?? + watchPage.root + .querySelector('meta[itemprop=uploadDate]') + ?.attributes['content'] + ?.tryParseDateTime(), + playerResponse.videoPublishDate ?? + watchPage.root + .querySelector('meta[itemprop=datePublished]') + ?.attributes['content'] + ?.tryParseDateTime(), playerResponse.videoDescription, playerResponse.videoDuration, ThumbnailSet(videoId.value), diff --git a/pubspec.yaml b/pubspec.yaml index f10886f..39a7e68 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.7 +version: 1.9.8+1 homepage: https://github.com/Hexer10/youtube_explode_dart diff --git a/test/video_test.dart b/test/video_test.dart index f58231f..2dd639c 100644 --- a/test/video_test.dart +++ b/test/video_test.dart @@ -19,13 +19,13 @@ void main() { expect(video.title, 'Aka no Ha [Another] +HDHR'); expect(video.channelId.value, 'UCEnBXANsKmyj2r9xVyKoDiQ'); expect(video.author, 'Tyrrrz'); -/* var rangeMs = DateTime(2017, 09, 30, 17, 15, 26).millisecondsSinceEpoch; + var rangeMs = DateTime(2017, 09, 30, 17, 15, 26).millisecondsSinceEpoch; // 1day margin since the uploadDate could differ from timezones // YouTube now doesn't send the upload date/ publish date anymore. expect(video.uploadDate!.millisecondsSinceEpoch, inInclusiveRange(rangeMs - 86400000, rangeMs + 86400000)); expect(video.publishDate!.millisecondsSinceEpoch, - inInclusiveRange(rangeMs - 86400000, rangeMs + 86400000));*/ + inInclusiveRange(rangeMs - 86400000, rangeMs + 86400000)); expect(video.description, contains('246pp')); // Should be 1:38 but sometimes it differs // so we're using a 10 seconds range from it. @@ -48,15 +48,28 @@ void main() { group('Get metadata of any video', () { for (final val in { - VideoId('9bZkp7q19f0'), - VideoId('SkRSXFQerZs'), - VideoId('5VGm0dczmHc'), - VideoId('ZGdLIwrGHG8'), - VideoId('5qap5aO4i9A') + VideoId('9bZkp7q19f0'), //Normal + VideoId('ZGdLIwrGHG8'), //Unlisted + VideoId('5qap5aO4i9A'), //LiveStream + VideoId('rsAAeyAr-9Y'), //LiveStreamRecording + VideoId('V5Fsj_sCKdg'), //ContainsHighQualityStreams + VideoId('AI7ULzgf8RU'), //ContainsDashManifest + VideoId('-xNN-bJQ4vI'), //Omnidirectional + VideoId('vX2vsvdq8nw'), //HighDynamicRange + VideoId('YltHGKX80Y8'), //ContainsClosedCaptions + VideoId('_kmeFXjjGfk'), //EmbedRestrictedByYouTube + VideoId('MeJVWBSsPAY'), //EmbedRestrictedByAuthor + VideoId('SkRSXFQerZs'), //AgeRestricted + VideoId('hySoCSoH-g8'), //AgeRestrictedEmbedRestricted + VideoId('5VGm0dczmHc'), //RatingDisabled + VideoId('p3dDcKOFXQg'), //RequiresPurchase }) { test('VideoId - ${val.value}', () async { var video = await yt!.videos.get(val); expect(video.id.value, val.value); + + expect(video.uploadDate, isNotNull); + expect(video.publishDate, isNotNull); }); } });