2016-12-18 09:49:10 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2021-02-04 07:56:01 +00:00
|
|
|
import datetime
|
2016-12-18 09:49:10 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
2018-04-21 21:55:35 +00:00
|
|
|
clean_html,
|
2016-12-18 09:49:10 +00:00
|
|
|
int_or_none,
|
|
|
|
parse_duration,
|
2018-04-21 21:55:35 +00:00
|
|
|
parse_resolution,
|
2021-02-04 07:56:01 +00:00
|
|
|
try_get,
|
2018-07-21 12:08:28 +00:00
|
|
|
url_or_none,
|
2016-12-18 09:49:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CCMAIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?ccma\.cat/(?:[^/]+/)*?(?P<type>video|audio)/(?P<id>\d+)'
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'http://www.ccma.cat/tv3/alacarta/lespot-de-la-marato-de-tv3/lespot-de-la-marato-de-tv3/video/5630208/',
|
|
|
|
'md5': '7296ca43977c8ea4469e719c609b0871',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '5630208',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'L\'espot de La Marató de TV3',
|
|
|
|
'description': 'md5:f12987f320e2f6e988e9908e4fe97765',
|
2021-02-04 07:56:01 +00:00
|
|
|
'timestamp': 1478608140,
|
|
|
|
'upload_date': '20161108',
|
|
|
|
'age_limit': 0,
|
2016-12-18 09:49:10 +00:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
'url': 'http://www.ccma.cat/catradio/alacarta/programa/el-consell-de-savis-analitza-el-derbi/audio/943685/',
|
|
|
|
'md5': 'fa3e38f269329a278271276330261425',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '943685',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'El Consell de Savis analitza el derbi',
|
|
|
|
'description': 'md5:e2a3648145f3241cb9c6b4b624033e53',
|
2021-02-04 07:56:01 +00:00
|
|
|
'upload_date': '20170512',
|
|
|
|
'timestamp': 1494622500,
|
|
|
|
'vcodec': 'none',
|
|
|
|
'categories': ['Esports'],
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
'url': 'http://www.ccma.cat/tv3/alacarta/crims/crims-josep-tallada-lespereu-me-capitol-1/video/6031387/',
|
|
|
|
'md5': 'b43c3d3486f430f3032b5b160d80cbc3',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '6031387',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Crims - Josep Talleda, l\'"Espereu-me" (capítol 1)',
|
|
|
|
'description': 'md5:7cbdafb640da9d0d2c0f62bad1e74e60',
|
|
|
|
'timestamp': 1582577700,
|
|
|
|
'upload_date': '20200224',
|
|
|
|
'subtitles': 'mincount:4',
|
|
|
|
'age_limit': 16,
|
|
|
|
'series': 'Crims',
|
2016-12-18 09:49:10 +00:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
media_type, media_id = re.match(self._VALID_URL, url).groups()
|
2018-04-21 21:55:35 +00:00
|
|
|
|
|
|
|
media = self._download_json(
|
|
|
|
'http://dinamics.ccma.cat/pvideo/media.jsp', media_id, query={
|
2016-12-18 09:49:10 +00:00
|
|
|
'media': media_type,
|
|
|
|
'idint': media_id,
|
2018-04-21 21:55:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
formats = []
|
|
|
|
media_url = media['media']['url']
|
|
|
|
if isinstance(media_url, list):
|
|
|
|
for format_ in media_url:
|
2018-07-21 12:08:28 +00:00
|
|
|
format_url = url_or_none(format_.get('file'))
|
|
|
|
if not format_url:
|
2018-04-21 21:55:35 +00:00
|
|
|
continue
|
|
|
|
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,
|
|
|
|
})
|
2016-12-18 09:49:10 +00:00
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2018-04-21 21:55:35 +00:00
|
|
|
informacio = media['informacio']
|
2016-12-18 09:49:10 +00:00
|
|
|
title = informacio['titol']
|
2021-02-04 07:56:01 +00:00
|
|
|
durada = informacio.get('durada') or {}
|
2016-12-18 09:49:10 +00:00
|
|
|
duration = int_or_none(durada.get('milisegons'), 1000) or parse_duration(durada.get('text'))
|
2021-02-04 07:56:01 +00:00
|
|
|
tematica = try_get(informacio, lambda x: x['tematica']['text'])
|
|
|
|
|
|
|
|
timestamp = None
|
|
|
|
data_utc = try_get(informacio, lambda x: x['data_emissio']['utc'])
|
|
|
|
try:
|
|
|
|
timestamp = datetime.datetime.strptime(
|
|
|
|
data_utc, '%Y-%d-%mT%H:%M:%S%z').timestamp()
|
|
|
|
except TypeError:
|
|
|
|
pass
|
2016-12-18 09:49:10 +00:00
|
|
|
|
|
|
|
subtitles = {}
|
2021-02-04 07:56:01 +00:00
|
|
|
subtitols = media.get('subtitols') or []
|
|
|
|
if isinstance(subtitols, dict):
|
|
|
|
subtitols = [subtitols]
|
|
|
|
for st in subtitols:
|
|
|
|
sub_url = st.get('url')
|
2016-12-18 09:49:10 +00:00
|
|
|
if sub_url:
|
|
|
|
subtitles.setdefault(
|
2021-02-04 07:56:01 +00:00
|
|
|
st.get('iso') or st.get('text') or 'ca', []).append({
|
2016-12-18 09:49:10 +00:00
|
|
|
'url': sub_url,
|
|
|
|
})
|
|
|
|
|
|
|
|
thumbnails = []
|
2018-04-21 21:55:35 +00:00
|
|
|
imatges = media.get('imatges', {})
|
2016-12-18 09:49:10 +00:00
|
|
|
if imatges:
|
|
|
|
thumbnail_url = imatges.get('url')
|
|
|
|
if thumbnail_url:
|
|
|
|
thumbnails = [{
|
|
|
|
'url': thumbnail_url,
|
|
|
|
'width': int_or_none(imatges.get('amplada')),
|
|
|
|
'height': int_or_none(imatges.get('alcada')),
|
|
|
|
}]
|
|
|
|
|
2021-02-04 07:56:01 +00:00
|
|
|
age_limit = None
|
|
|
|
codi_etic = try_get(informacio, lambda x: x['codi_etic']['id'])
|
|
|
|
if codi_etic:
|
|
|
|
codi_etic_s = codi_etic.split('_')
|
|
|
|
if len(codi_etic_s) == 2:
|
|
|
|
if codi_etic_s[1] == 'TP':
|
|
|
|
age_limit = 0
|
|
|
|
else:
|
|
|
|
age_limit = int_or_none(codi_etic_s[1])
|
|
|
|
|
2016-12-18 09:49:10 +00:00
|
|
|
return {
|
|
|
|
'id': media_id,
|
|
|
|
'title': title,
|
|
|
|
'description': clean_html(informacio.get('descripcio')),
|
|
|
|
'duration': duration,
|
|
|
|
'timestamp': timestamp,
|
2017-11-12 06:25:21 +00:00
|
|
|
'thumbnails': thumbnails,
|
2016-12-18 09:49:10 +00:00
|
|
|
'subtitles': subtitles,
|
|
|
|
'formats': formats,
|
2021-02-04 07:56:01 +00:00
|
|
|
'age_limit': age_limit,
|
|
|
|
'alt_title': informacio.get('titol_complet'),
|
|
|
|
'episode_number': int_or_none(informacio.get('capitol')),
|
|
|
|
'categories': [tematica] if tematica else None,
|
|
|
|
'series': informacio.get('programa'),
|
2016-12-18 09:49:10 +00:00
|
|
|
}
|