From dcedede9e967c3ca3bc488e9801a0a7e41a15a4c Mon Sep 17 00:00:00 2001 From: Mattia Date: Tue, 12 Sep 2023 14:18:14 +0200 Subject: [PATCH] Better performance for iterating through closed captions elements. Closes #251 . Version bump --- CHANGELOG.md | 4 ++++ .../closed_caption_client.dart | 20 ++++++++++--------- pubspec.yaml | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 998caca..f82679a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.3 +- Better performance for iterating through closed captions elements. #251 + + ## 2.0.2 - Implement YT Handles. - Deprecated ChannelLink icon's uri, they are no longer provided by YT. diff --git a/lib/src/videos/closed_captions/closed_caption_client.dart b/lib/src/videos/closed_captions/closed_caption_client.dart index 80a79e6..39803de 100644 --- a/lib/src/videos/closed_captions/closed_caption_client.dart +++ b/lib/src/videos/closed_captions/closed_caption_client.dart @@ -59,15 +59,17 @@ class ClosedCaptionClient { final response = await re.ClosedCaptionClient.get(_httpClient, trackInfo.url); - final captions = - response.closedCaptions.where((e) => !e.text.isNullOrWhiteSpace).map( - (e) => ClosedCaption( - e.text, - e.offset, - e.duration, - e.parts.map((f) => ClosedCaptionPart(f.text, f.offset)), - ), - ); + final captions = [ + for (final e in response.closedCaptions) + if (!e.text.isNullOrWhiteSpace) + ClosedCaption( + e.text, + e.offset, + e.duration, + e.parts.map((f) => ClosedCaptionPart(f.text, f.offset)), + ), + ]; + return ClosedCaptionTrack(captions); } diff --git a/pubspec.yaml b/pubspec.yaml index e1741c3..6206da8 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: 2.0.2 +version: 2.0.3 homepage: https://github.com/Hexer10/youtube_explode_dart topics: