Merge pull request #9 from Hexer10/pull/8

Address PR request. #8
This commit is contained in:
Mattia 2020-02-21 21:58:00 +01:00 committed by GitHub
commit eaec4a071e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

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