Address PR request. #8

This commit is contained in:
Hexah 2020-02-21 21:55:49 +01:00
parent e9b67691ef
commit 94ea6a88b0
1 changed files with 7 additions and 5 deletions

View File

@ -231,7 +231,7 @@ class YoutubeExplode {
videoInfo['shortDescription'], videoInfo['shortDescription'],
ThumbnailSet(videoId), ThumbnailSet(videoId),
Duration(seconds: int.parse(videoInfo['lengthSeconds'])), Duration(seconds: int.parse(videoInfo['lengthSeconds'])),
videoInfo['keywords']?.cast<String>(), videoInfo['keywords']?.cast<String>() ?? const <String>[],
Statistics(int.parse(videoInfo['viewCount']), 0, 0)); Statistics(int.parse(videoInfo['viewCount']), 0, 0));
var streamingData = playerResponseJson['streamingData']; var streamingData = playerResponseJson['streamingData'];
@ -297,7 +297,7 @@ class YoutubeExplode {
var author = details['author']; var author = details['author'];
var description = details['shortDescription']; var description = details['shortDescription'];
var duration = Duration(seconds: int.parse(details['lengthSeconds'])); var duration = Duration(seconds: int.parse(details['lengthSeconds']));
var keyWords = details['keywords']?.cast<String>(); var keyWords = details['keywords']?.cast<String>() ?? const <String>[];
var viewCount = int.tryParse(details['viewCount'] ?? '0') ?? 0; var viewCount = int.tryParse(details['viewCount'] ?? '0') ?? 0;
var videoPageHtml = await _getVideoWatchPageHtml(videoId); var videoPageHtml = await _getVideoWatchPageHtml(videoId);
@ -345,11 +345,13 @@ class YoutubeExplode {
Future<int> _requestContentLength(String url) async { Future<int> _requestContentLength(String url) async {
var resp; var resp;
try { try {
resp = await http.head(url); resp = await client.head(url);
} on Exception catch (e) { } on Exception {
return -1;
}
if (!resp.headers.containsKey('content-length')) {
return -1; return -1;
} }
if (!resp.headers.containsKey('content-length')) return -1;
String contentLengthString = resp.headers['content-length']; String contentLengthString = resp.headers['content-length'];
return int.tryParse(contentLengthString ?? '') ?? -1; return int.tryParse(contentLengthString ?? '') ?? -1;
} }