diff --git a/CHANGELOG.md b/CHANGELOG.md index e8f029f..5cfb050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ +## 1.9.2 +- Implement `videoDuration` in `ChannelVideo`. + ## 1.9.1 -- Bug fixes (due to youtube changes) +- Bug fixes (due to YouTube changes) ## 1.9.0 - Support nnbd (dart 1.12) diff --git a/lib/src/channels/channel_video.dart b/lib/src/channels/channel_video.dart index 1721d61..954d7ae 100644 --- a/lib/src/channels/channel_video.dart +++ b/lib/src/channels/channel_video.dart @@ -9,8 +9,11 @@ class ChannelVideo with EquatableMixin { /// Video title. final String videoTitle; + /// Video duration + final Duration videoDuration; + /// Initialize an instance of [ChannelVideo] - ChannelVideo(this.videoId, this.videoTitle); + ChannelVideo(this.videoId, this.videoTitle, this.videoDuration); @override String toString() => '[ChannelVideo] $videoTitle ($videoId)'; diff --git a/lib/src/reverse_engineering/responses/channel_upload_page.dart b/lib/src/reverse_engineering/responses/channel_upload_page.dart index f2a7667..8b115eb 100644 --- a/lib/src/reverse_engineering/responses/channel_upload_page.dart +++ b/lib/src/reverse_engineering/responses/channel_upload_page.dart @@ -166,6 +166,16 @@ class _InitialData { VideoId(video.getT('videoId')!), video.get('title')?.getT('simpleText') ?? video.get('title')?.getList('runs')?.map((e) => e['text']).join() ?? - ''); + '', + video + .getList('thumbnailOverlays') + ?.firstOrNull + ?.get('thumbnailOverlayTimeStatusRenderer') + ?.get('text') + ?.getT('simpleText') + ?.toDuration() ?? + Duration.zero); } } + +// video['thumbnailOverlays'].first['thumbnailOverlayTimeStatusRenderer']['text']['simpleText'] diff --git a/lib/src/reverse_engineering/responses/playlist_page.dart b/lib/src/reverse_engineering/responses/playlist_page.dart index c3ac8bb..739158b 100644 --- a/lib/src/reverse_engineering/responses/playlist_page.dart +++ b/lib/src/reverse_engineering/responses/playlist_page.dart @@ -219,33 +219,8 @@ class _Video { root.getList('descriptionSnippet')?.parseRuns() ?? ''; Duration? get duration => - _stringToDuration(root.get('lengthText')?.getT('simpleText')); + root.get('lengthText')?.getT('simpleText')?.toDuration(); int get viewCount => root.get('viewCountText')?.getT('simpleText')?.parseInt() ?? 0; - - /// Format: HH:MM:SS - static Duration? _stringToDuration(String? string) { - if (string == null || string.trim().isEmpty) { - return null; - } - - var parts = string.split(':'); - assert(parts.length <= 3); - - if (parts.length == 1) { - return Duration(seconds: int.parse(parts.first)); - } - if (parts.length == 2) { - return Duration( - minutes: int.parse(parts.first), seconds: int.parse(parts[1])); - } - if (parts.length == 3) { - return Duration( - hours: int.parse(parts[0]), - minutes: int.parse(parts[1]), - seconds: int.parse(parts[2])); - } - throw Error(); - } } diff --git a/test/channel_test.dart b/test/channel_test.dart index 5ff204f..f1da5e3 100644 --- a/test/channel_test.dart +++ b/test/channel_test.dart @@ -65,6 +65,7 @@ void main() { } }); + test('Get videos of a youtube channel from the uploads page', () async { var videos = await yt!.channels .getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ')