[PeerTube] Add various safety precautions
This commit is contained in:
parent
05a1a553b9
commit
d96b295a32
@ -7,6 +7,7 @@ from .common import InfoExtractor
|
|||||||
from ..compat import compat_str
|
from ..compat import compat_str
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
str_or_none,
|
||||||
parse_resolution,
|
parse_resolution,
|
||||||
try_get,
|
try_get,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
@ -491,20 +492,18 @@ class PeerTubeIE(InfoExtractor):
|
|||||||
|
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
for entry in video_captions.get('data'):
|
for entry in video_captions.get('data'):
|
||||||
captions_language = entry.get('language')
|
language_id = try_get(entry, lambda x: x['language']['id'], compat_str)
|
||||||
if captions_language is not None:
|
caption_path = str_or_none(entry.get('captionPath'))
|
||||||
language_id = captions_language.get('id')
|
if language_id and caption_path:
|
||||||
caption_path = entry.get('captionPath')
|
caption_url = 'https://%s%s' % (host, caption_path)
|
||||||
if language_id is not None and caption_path is not None:
|
if language_id in subtitles:
|
||||||
caption_url = 'https://%s%s' % (host, caption_path)
|
subtitles[language_id].append({
|
||||||
if language_id in subtitles:
|
'url': caption_url
|
||||||
subtitles[language_id].append({
|
})
|
||||||
'url': caption_url
|
else:
|
||||||
})
|
subtitles[language_id] = [{
|
||||||
else:
|
'url': caption_url
|
||||||
subtitles[language_id] = [{
|
}]
|
||||||
'url': caption_url
|
|
||||||
}]
|
|
||||||
return subtitles
|
return subtitles
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
@ -515,13 +514,13 @@ class PeerTubeIE(InfoExtractor):
|
|||||||
video = self._download_json(
|
video = self._download_json(
|
||||||
'https://%s/api/v1/videos/%s' % (host, video_id), video_id)
|
'https://%s/api/v1/videos/%s' % (host, video_id), video_id)
|
||||||
|
|
||||||
title = video['name']
|
title = video.get('name')
|
||||||
|
|
||||||
video_description = self._download_json(
|
video_description = self._download_json(
|
||||||
'https://%s/api/v1/videos/%s/description' % (host, video_id), video_id, fatal=False)
|
'https://%s/api/v1/videos/%s/description' % (host, video_id), video_id, fatal=False)
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for file_ in video['files']:
|
for file_ in video.get('files'):
|
||||||
if not isinstance(file_, dict):
|
if not isinstance(file_, dict):
|
||||||
continue
|
continue
|
||||||
file_url = url_or_none(file_.get('fileUrl'))
|
file_url = url_or_none(file_.get('fileUrl'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user