[ccma] Fix video extraction (closes #15931)

This commit is contained in:
Sergey M․ 2018-04-22 04:55:35 +07:00
parent a693386df1
commit 040c6296bb
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -4,11 +4,13 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import ( from ..utils import (
clean_html,
int_or_none, int_or_none,
parse_duration, parse_duration,
parse_iso8601, parse_iso8601,
clean_html, parse_resolution,
) )
@ -40,34 +42,42 @@ class CCMAIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
media_type, media_id = re.match(self._VALID_URL, url).groups() media_type, media_id = re.match(self._VALID_URL, url).groups()
media_data = {}
formats = [] media = self._download_json(
profiles = ['pc'] if media_type == 'audio' else ['mobil', 'pc'] 'http://dinamics.ccma.cat/pvideo/media.jsp', media_id, query={
for i, profile in enumerate(profiles):
md = self._download_json('http://dinamics.ccma.cat/pvideo/media.jsp', media_id, query={
'media': media_type, 'media': media_type,
'idint': media_id, 'idint': media_id,
'profile': profile, })
}, fatal=False)
if md: formats = []
media_data = md media_url = media['media']['url']
media_url = media_data.get('media', {}).get('url') if isinstance(media_url, list):
if media_url: for format_ in media_url:
formats.append({ format_url = format_.get('file')
'format_id': profile, if not format_url or not isinstance(format_url, compat_str):
'url': media_url, continue
'quality': i, label = format_.get('label')
}) f = parse_resolution(label)
f.update({
'url': format_url,
'format_id': label,
})
formats.append(f)
else:
formats.append({
'url': media_url,
'vcodec': 'none' if media_type == 'audio' else None,
})
self._sort_formats(formats) self._sort_formats(formats)
informacio = media_data['informacio'] informacio = media['informacio']
title = informacio['titol'] title = informacio['titol']
durada = informacio.get('durada', {}) durada = informacio.get('durada', {})
duration = int_or_none(durada.get('milisegons'), 1000) or parse_duration(durada.get('text')) duration = int_or_none(durada.get('milisegons'), 1000) or parse_duration(durada.get('text'))
timestamp = parse_iso8601(informacio.get('data_emissio', {}).get('utc')) timestamp = parse_iso8601(informacio.get('data_emissio', {}).get('utc'))
subtitles = {} subtitles = {}
subtitols = media_data.get('subtitols', {}) subtitols = media.get('subtitols', {})
if subtitols: if subtitols:
sub_url = subtitols.get('url') sub_url = subtitols.get('url')
if sub_url: if sub_url:
@ -77,7 +87,7 @@ class CCMAIE(InfoExtractor):
}) })
thumbnails = [] thumbnails = []
imatges = media_data.get('imatges', {}) imatges = media.get('imatges', {})
if imatges: if imatges:
thumbnail_url = imatges.get('url') thumbnail_url = imatges.get('url')
if thumbnail_url: if thumbnail_url: