]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/rtp.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / rtp.py
CommitLineData
c3f3b29b
NJ
1# coding: utf-8
2from __future__ import unicode_literals
3
c3f3b29b 4from .common import InfoExtractor
ead467a9
RA
5from ..utils import (
6 determine_ext,
7 js_to_json,
8)
c3f3b29b
NJ
9
10
11class RTPIE(InfoExtractor):
bad5c1a3
PH
12 _VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
13 _TESTS = [{
c3f3b29b 14 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
ad5747ba 15 'md5': 'e736ce0c665e459ddb818546220b4ef8',
c3f3b29b 16 'info_dict': {
a86cbf58 17 'id': 'e174042',
c3f3b29b
NJ
18 'ext': 'mp3',
19 'title': 'Paixões Cruzadas',
20 'description': 'As paixões musicais de António Cartaxo e António Macedo',
ec85ded8 21 'thumbnail': r're:^https?://.*\.jpg',
c3f3b29b 22 },
bad5c1a3
PH
23 }, {
24 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
25 'only_matching': True,
26 }]
c3f3b29b
NJ
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30
31 webpage = self._download_webpage(url, video_id)
32 title = self._html_search_meta(
33 'twitter:title', webpage, display_name='title', fatal=True)
ad5747ba 34
ead467a9
RA
35 config = self._parse_json(self._search_regex(
36 r'(?s)RTPPlayer\(({.+?})\);', webpage,
37 'player config'), video_id, js_to_json)
38 file_url = config['file']
39 ext = determine_ext(file_url)
40 if ext == 'm3u8':
41 file_key = config.get('fileKey')
42 formats = self._extract_m3u8_formats(
43 file_url, video_id, 'mp4', 'm3u8_native',
44 m3u8_id='hls', fatal=file_key)
45 if file_key:
46 formats.append({
47 'url': 'https://cdn-ondemand.rtp.pt' + file_key,
f983b875 48 'quality': 1,
ead467a9
RA
49 })
50 self._sort_formats(formats)
51 else:
52 formats = [{
53 'url': file_url,
54 'ext': ext,
55 }]
56 if config.get('mediaType') == 'audio':
57 for f in formats:
58 f['vcodec'] = 'none'
ad5747ba 59
c3f3b29b
NJ
60 return {
61 'id': video_id,
62 'title': title,
63 'formats': formats,
ead467a9
RA
64 'description': self._html_search_meta(['description', 'twitter:description'], webpage),
65 'thumbnail': config.get('poster') or self._og_search_thumbnail(webpage),
c3f3b29b 66 }