From 0ce24bf0178571a0fd2706539b8b94db32a7ede3 Mon Sep 17 00:00:00 2001 From: Mattia Date: Thu, 3 Mar 2022 12:11:02 +0100 Subject: [PATCH] Fix #194: allow malformed utf8 Version 1.10.10+2 --- CHANGELOG.md | 3 +++ .../closed_captions/closed_caption_client.dart | 13 +++++++++---- pubspec.yaml | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1046895..cde0e7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.10.10+2 +- Fix #194: Now closed-captions allow malformed utf8 as well. + ## 1.10.10+1 - Deprecated `withHighestBitrate()` in favour of `bestQuality`. diff --git a/lib/src/videos/closed_captions/closed_caption_client.dart b/lib/src/videos/closed_captions/closed_caption_client.dart index 52a2a9d..5f7be85 100644 --- a/lib/src/videos/closed_captions/closed_caption_client.dart +++ b/lib/src/videos/closed_captions/closed_caption_client.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import '../../extensions/helpers_extension.dart'; import '../../reverse_engineering/clients/closed_caption_client.dart' as re show ClosedCaptionClient; @@ -28,7 +30,8 @@ class ClosedCaptionClient { ]}) async { videoId = VideoId.fromString(videoId); var tracks = {}; - var watchPage = await WatchPage.get(_httpClient, (videoId as VideoId).value); + var watchPage = + await WatchPage.get(_httpClient, (videoId as VideoId).value); var playerResponse = watchPage.playerResponse!; for (final track in playerResponse.closedCaptionTrack) { @@ -56,7 +59,9 @@ class ClosedCaptionClient { return ClosedCaptionTrack(captions); } - /// Returns the subtitles as a string. - Future getSubTitles(ClosedCaptionTrackInfo trackInfo) => - _httpClient.getString(trackInfo.url); + /// Returns the subtitles as a string. In XML format. + Future getSubTitles(ClosedCaptionTrackInfo trackInfo) async { + final r = await _httpClient.get(trackInfo.url); + return utf8.decode(r.bodyBytes, allowMalformed: true); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 0681b15..df0c705 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.10.10+1 +version: 1.10.10+2 homepage: https://github.com/Hexer10/youtube_explode_dart