1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-26 10:24:33 +01:00

Fix JSON fetching and subtitles validation

This commit is contained in:
thePanz 2019-11-08 12:15:45 +01:00
parent 095f9df2ad
commit 8815646ce3

View File

@ -15,12 +15,14 @@ from ..utils import (
GeoRestrictedError, GeoRestrictedError,
int_or_none, int_or_none,
parse_duration, parse_duration,
str_or_none,
strip_or_none, strip_or_none,
try_get, try_get,
unescapeHTML, unescapeHTML,
unified_strdate, unified_strdate,
unified_timestamp, unified_timestamp,
update_url_query, update_url_query,
url_or_none,
urljoin, urljoin,
xpath_text, xpath_text,
) )
@ -102,8 +104,7 @@ class RaiBaseIE(InfoExtractor):
}.items() if v is not None) }.items() if v is not None)
@staticmethod @staticmethod
def _extract_subtitles(url, subtitle_url): def _extract_subtitles(url, subtitle_url, subtitles):
subtitles = {}
if subtitle_url and isinstance(subtitle_url, compat_str): if subtitle_url and isinstance(subtitle_url, compat_str):
subtitle_url = urljoin(url, subtitle_url) subtitle_url = urljoin(url, subtitle_url)
STL_EXT = '.stl' STL_EXT = '.stl'
@ -121,13 +122,12 @@ class RaiBaseIE(InfoExtractor):
return subtitles return subtitles
@staticmethod @staticmethod
def _extract_subtitles_from_list(subtitle_array): def _extract_subtitles_from_list(subtitle_array, subtitles):
subtitles = {}
if isinstance(subtitle_array, list): if isinstance(subtitle_array, list):
for item in subtitle_array: for item in subtitle_array:
lang = item.get('language') lang = item.get('language')
url = item.get('url') url = item.get('url')
if isinstance(url, compat_str) and '' != url and isinstance(lang, compat_str) and '' != lang: if url_or_none(url) and str_or_none(lang):
subtitles[lang.lower()] = [{ subtitles[lang.lower()] = [{
'ext': url[-3:], 'ext': url[-3:],
'url': url, 'url': url,
@ -158,21 +158,16 @@ class RaiPlayIE(RaiBaseIE):
'url': 'https://www.raiplay.it/video/2019/10/Report-del-21102019-La-fabbrica-della-paura-825ce3a7-8573-46c8-80d2-cde1b519fd01.html', 'url': 'https://www.raiplay.it/video/2019/10/Report-del-21102019-La-fabbrica-della-paura-825ce3a7-8573-46c8-80d2-cde1b519fd01.html',
'md5': '8970abf8caf8aef4696e7b1f2adfc696', 'md5': '8970abf8caf8aef4696e7b1f2adfc696',
'info_dict': { 'info_dict': {
"id": "825ce3a7-8573-46c8-80d2-cde1b519fd01", 'id': '825ce3a7-8573-46c8-80d2-cde1b519fd01',
"title": "Report - La fabbrica della paura", 'title': 'Report - La fabbrica della paura',
"alt_title": "St 2019/20 - La fabbrica della paura - 21/10/2019 ", 'alt_title': 'St 2019/20 - La fabbrica della paura - 21/10/2019 ',
'description': 'md5:f27c544694cacb46a078db84ec35d2d9', 'description': 'md5:f27c544694cacb46a078db84ec35d2d9',
"ext": "mp4", 'ext': 'mp4',
"series": "Report", 'series': 'Report',
"season_number": 7, 'season_number': 7,
"season": "2019/20", 'season': '2019/20',
"subtitles": { 'subtitles': {
"it": [ 'it': [{'ext': 'srt'}]
{
"ext": "srt",
"url": "http://creativemedia4-rai-it.akamaized.net/infocdn/raitre/report/Report_EP_Puntate/11217587.srt"
}
]
}, },
}, },
'params': { 'params': {
@ -187,14 +182,13 @@ class RaiPlayIE(RaiBaseIE):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
url, video_id = mobj.group('url', 'id') url, video_id = mobj.group('url', 'id')
media = self._download_json( media = self._download_json(url.replace('.html', '.json'), video_id, 'Downloading video JSON')
'%s?json' % url, video_id, 'Downloading video JSON')
title = media['name'] title = media['name']
video = media['video'] video = media['video']
relinker_info = self._extract_relinker_info(video['contentUrl'], video_id) relinker_info = self._extract_relinker_info(video['content_url'], video_id)
self._sort_formats(relinker_info['formats']) self._sort_formats(relinker_info['formats'])
thumbnails = [] thumbnails = []
@ -210,10 +204,9 @@ class RaiPlayIE(RaiBaseIE):
subtitles = {} subtitles = {}
if '' != video.get('subtitles'): if '' != video.get('subtitles'):
subtitles = self._extract_subtitles(url, video.get('subtitles')) subtitles = self._extract_subtitles(url, video.get('subtitles'), subtitles)
else: if video.get('subtitlesArray'):
if video.get('subtitlesArray'): subtitles = self._extract_subtitles_from_list(video.get('subtitlesArray'), subtitles)
subtitles = self._extract_subtitles_from_list(video.get('subtitlesArray'))
info = { info = {
'id': video_id, 'id': video_id,
'title': self._live_title(title) if relinker_info.get( 'title': self._live_title(title) if relinker_info.get(