]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/ccma.py
[VideoConvertor] Ensure all streams are copied
[yt-dlp.git] / yt_dlp / extractor / ccma.py
CommitLineData
199a47ab
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
199a47ab
RA
4from .common import InfoExtractor
5from ..utils import (
040c6296 6 clean_html,
199a47ab
RA
7 int_or_none,
8 parse_duration,
040c6296 9 parse_resolution,
2181983a 10 try_get,
e66662b1 11 unified_timestamp,
3052a30d 12 url_or_none,
199a47ab
RA
13)
14
15
16class CCMAIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?ccma\.cat/(?:[^/]+/)*?(?P<type>video|audio)/(?P<id>\d+)'
18 _TESTS = [{
19 'url': 'http://www.ccma.cat/tv3/alacarta/lespot-de-la-marato-de-tv3/lespot-de-la-marato-de-tv3/video/5630208/',
20 'md5': '7296ca43977c8ea4469e719c609b0871',
21 'info_dict': {
22 'id': '5630208',
23 'ext': 'mp4',
24 'title': 'L\'espot de La Marató de TV3',
25 'description': 'md5:f12987f320e2f6e988e9908e4fe97765',
2181983a 26 'timestamp': 1478608140,
27 'upload_date': '20161108',
28 'age_limit': 0,
199a47ab
RA
29 }
30 }, {
31 'url': 'http://www.ccma.cat/catradio/alacarta/programa/el-consell-de-savis-analitza-el-derbi/audio/943685/',
32 'md5': 'fa3e38f269329a278271276330261425',
33 'info_dict': {
34 'id': '943685',
35 'ext': 'mp3',
36 'title': 'El Consell de Savis analitza el derbi',
37 'description': 'md5:e2a3648145f3241cb9c6b4b624033e53',
2181983a 38 'upload_date': '20170512',
39 'timestamp': 1494622500,
40 'vcodec': 'none',
41 'categories': ['Esports'],
42 }
43 }, {
44 'url': 'http://www.ccma.cat/tv3/alacarta/crims/crims-josep-tallada-lespereu-me-capitol-1/video/6031387/',
45 'md5': 'b43c3d3486f430f3032b5b160d80cbc3',
46 'info_dict': {
47 'id': '6031387',
48 'ext': 'mp4',
49 'title': 'Crims - Josep Talleda, l\'"Espereu-me" (capítol 1)',
50 'description': 'md5:7cbdafb640da9d0d2c0f62bad1e74e60',
51 'timestamp': 1582577700,
52 'upload_date': '20200224',
53 'subtitles': 'mincount:4',
54 'age_limit': 16,
55 'series': 'Crims',
199a47ab
RA
56 }
57 }]
58
59 def _real_extract(self, url):
5ad28e7f 60 media_type, media_id = self._match_valid_url(url).groups()
040c6296
S
61
62 media = self._download_json(
63 'http://dinamics.ccma.cat/pvideo/media.jsp', media_id, query={
199a47ab
RA
64 'media': media_type,
65 'idint': media_id,
040c6296
S
66 })
67
68 formats = []
69 media_url = media['media']['url']
70 if isinstance(media_url, list):
71 for format_ in media_url:
3052a30d
S
72 format_url = url_or_none(format_.get('file'))
73 if not format_url:
040c6296
S
74 continue
75 label = format_.get('label')
76 f = parse_resolution(label)
77 f.update({
78 'url': format_url,
79 'format_id': label,
80 })
81 formats.append(f)
82 else:
83 formats.append({
84 'url': media_url,
85 'vcodec': 'none' if media_type == 'audio' else None,
86 })
199a47ab
RA
87 self._sort_formats(formats)
88
040c6296 89 informacio = media['informacio']
199a47ab 90 title = informacio['titol']
2181983a 91 durada = informacio.get('durada') or {}
199a47ab 92 duration = int_or_none(durada.get('milisegons'), 1000) or parse_duration(durada.get('text'))
2181983a 93 tematica = try_get(informacio, lambda x: x['tematica']['text'])
94
2181983a 95 data_utc = try_get(informacio, lambda x: x['data_emissio']['utc'])
e66662b1 96 timestamp = unified_timestamp(data_utc)
199a47ab
RA
97
98 subtitles = {}
2181983a 99 subtitols = media.get('subtitols') or []
100 if isinstance(subtitols, dict):
101 subtitols = [subtitols]
102 for st in subtitols:
103 sub_url = st.get('url')
199a47ab
RA
104 if sub_url:
105 subtitles.setdefault(
2181983a 106 st.get('iso') or st.get('text') or 'ca', []).append({
199a47ab
RA
107 'url': sub_url,
108 })
109
110 thumbnails = []
040c6296 111 imatges = media.get('imatges', {})
199a47ab
RA
112 if imatges:
113 thumbnail_url = imatges.get('url')
114 if thumbnail_url:
115 thumbnails = [{
116 'url': thumbnail_url,
117 'width': int_or_none(imatges.get('amplada')),
118 'height': int_or_none(imatges.get('alcada')),
119 }]
120
2181983a 121 age_limit = None
122 codi_etic = try_get(informacio, lambda x: x['codi_etic']['id'])
123 if codi_etic:
124 codi_etic_s = codi_etic.split('_')
125 if len(codi_etic_s) == 2:
126 if codi_etic_s[1] == 'TP':
127 age_limit = 0
128 else:
129 age_limit = int_or_none(codi_etic_s[1])
130
199a47ab
RA
131 return {
132 'id': media_id,
133 'title': title,
134 'description': clean_html(informacio.get('descripcio')),
135 'duration': duration,
136 'timestamp': timestamp,
af85ce29 137 'thumbnails': thumbnails,
199a47ab
RA
138 'subtitles': subtitles,
139 'formats': formats,
2181983a 140 'age_limit': age_limit,
141 'alt_title': informacio.get('titol_complet'),
142 'episode_number': int_or_none(informacio.get('capitol')),
143 'categories': [tematica] if tematica else None,
144 'series': informacio.get('programa'),
199a47ab 145 }