[PeerTube] Improve safety of description extraction

This commit is contained in:
3risian 2020-01-09 13:40:54 +11:00 committed by GitHub
parent 1e8781843f
commit 39af4a84b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -516,9 +516,6 @@ class PeerTubeIE(InfoExtractor):
title = video.get('name') title = video.get('name')
video_description = self._download_json(
'https://%s/api/v1/videos/%s/description' % (host, video_id), video_id, fatal=False)
formats = [] formats = []
for file_ in video.get('files'): for file_ in video.get('files'):
if not isinstance(file_, dict): if not isinstance(file_, dict):
@ -538,6 +535,13 @@ class PeerTubeIE(InfoExtractor):
formats.append(f) formats.append(f)
self._sort_formats(formats) self._sort_formats(formats)
video_description = self._download_json(
'https://%s/api/v1/videos/%s/description' % (host, video_id), video_id, fatal=False)
description = ""
if video_description:
description = video_description.get('description')
subtitles = self.extract_subtitles(host, video_id) subtitles = self.extract_subtitles(host, video_id)
def account_data(field): def account_data(field):
@ -558,7 +562,7 @@ class PeerTubeIE(InfoExtractor):
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'description': video_description.get('description'), 'description': description,
'thumbnail': urljoin(url, video.get('thumbnailPath')), 'thumbnail': urljoin(url, video.get('thumbnailPath')),
'timestamp': unified_timestamp(video.get('publishedAt')), 'timestamp': unified_timestamp(video.get('publishedAt')),
'uploader': account_data('displayName'), 'uploader': account_data('displayName'),