]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/performgroup.py
[extractor] Common function `_match_valid_url`
[yt-dlp.git] / yt_dlp / extractor / performgroup.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import int_or_none
7
8
9 class PerformGroupIE(InfoExtractor):
10 _VALID_URL = r'https?://player\.performgroup\.com/eplayer(?:/eplayer\.html|\.js)#/?(?P<id>[0-9a-f]{26})\.(?P<auth_token>[0-9a-z]{26})'
11 _TESTS = [{
12 # http://www.faz.net/aktuell/sport/fussball/wm-2018-playoffs-schweiz-besiegt-nordirland-1-0-15286104.html
13 'url': 'http://player.performgroup.com/eplayer/eplayer.html#d478c41c5d192f56b9aa859de8.1w4crrej5w14e1ed4s1ce4ykab',
14 'md5': '259cb03d142e2e52471e8837ecacb29f',
15 'info_dict': {
16 'id': 'xgrwobuzumes1lwjxtcdpwgxd',
17 'ext': 'mp4',
18 'title': 'Liga MX: Keine Einsicht nach Horrorfoul',
19 'description': 'md5:7cd3b459c82725b021e046ab10bf1c5b',
20 'timestamp': 1511533477,
21 'upload_date': '20171124',
22 }
23 }]
24
25 def _call_api(self, service, auth_token, content_id, referer_url):
26 return self._download_json(
27 'http://ep3.performfeeds.com/ep%s/%s/%s/' % (service, auth_token, content_id),
28 content_id, headers={
29 'Referer': referer_url,
30 'Origin': 'http://player.performgroup.com',
31 }, query={
32 '_fmt': 'json',
33 })
34
35 def _real_extract(self, url):
36 player_id, auth_token = self._match_valid_url(url).groups()
37 bootstrap = self._call_api('bootstrap', auth_token, player_id, url)
38 video = bootstrap['config']['dataSource']['sourceItems'][0]['videos'][0]
39 video_id = video['uuid']
40 vod = self._call_api('vod', auth_token, video_id, url)
41 media = vod['videos']['video'][0]['media']
42
43 formats = []
44 hls_url = media.get('hls', {}).get('url')
45 if hls_url:
46 formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
47
48 hds_url = media.get('hds', {}).get('url')
49 if hds_url:
50 formats.extend(self._extract_f4m_formats(hds_url + '?hdcore', video_id, f4m_id='hds', fatal=False))
51
52 for c in media.get('content', []):
53 c_url = c.get('url')
54 if not c_url:
55 continue
56 tbr = int_or_none(c.get('bitrate'), 1000)
57 format_id = 'http'
58 if tbr:
59 format_id += '-%d' % tbr
60 formats.append({
61 'format_id': format_id,
62 'url': c_url,
63 'tbr': tbr,
64 'width': int_or_none(c.get('width')),
65 'height': int_or_none(c.get('height')),
66 'filesize': int_or_none(c.get('fileSize')),
67 'vcodec': c.get('type'),
68 'fps': int_or_none(c.get('videoFrameRate')),
69 'vbr': int_or_none(c.get('videoRate'), 1000),
70 'abr': int_or_none(c.get('audioRate'), 1000),
71 })
72 self._sort_formats(formats)
73
74 return {
75 'id': video_id,
76 'title': video['title'],
77 'description': video.get('description'),
78 'thumbnail': video.get('poster'),
79 'duration': int_or_none(video.get('duration')),
80 'timestamp': int_or_none(video.get('publishedTime'), 1000),
81 'formats': formats,
82 }