youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

performgroup.py (3355B)


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