]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/audimedia.py
   2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
  11 class AudiMediaIE(InfoExtractor
): 
  12     _VALID_URL 
= r
'https?://(?:www\.)?audi-mediacenter\.com/(?:en|de)/audimediatv/(?:video/)?(?P<id>[^/?#]+)' 
  14         'url': 'https://www.audi-mediacenter.com/en/audimediatv/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-1467', 
  15         'md5': '79a8b71c46d49042609795ab59779b66', 
  19             'title': '60 Seconds of Audi Sport 104/2015 - WEC Bahrain, Rookie Test', 
  20             'description': 'md5:60e5d30a78ced725f7b8d34370762941', 
  21             'upload_date': '20151124', 
  22             'timestamp': 1448354940, 
  27         'url': 'https://www.audi-mediacenter.com/en/audimediatv/video/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-2991', 
  28         'only_matching': True, 
  31     def _real_extract(self
, url
): 
  32         display_id 
= self
._match
_id
(url
) 
  33         webpage 
= self
._download
_webpage
(url
, display_id
) 
  35         raw_payload 
= self
._search
_regex
([ 
  36             r
'class="amtv-embed"[^>]+id="([0-9a-z-]+)"', 
  37             r
'id="([0-9a-z-]+)"[^>]+class="amtv-embed"', 
  38             r
'class=\\"amtv-embed\\"[^>]+id=\\"([0-9a-z-]+)\\"', 
  39             r
'id=\\"([0-9a-z-]+)\\"[^>]+class=\\"amtv-embed\\"', 
  40             r
'id=(?:\\)?"(amtve-[a-z]-\d+-[a-z]{2})', 
  41         ], webpage
, 'raw payload') 
  42         _
, stage_mode
, video_id
, _ 
= raw_payload
.split('-') 
  44         # TODO: handle s and e stage_mode (live streams and ended live streams) 
  45         if stage_mode 
not in ('s', 'e'): 
  46             video_data 
= self
._download
_json
( 
  47                 'https://www.audimedia.tv/api/video/v1/videos/' + video_id
, 
  49                     'embed[]': ['video_versions', 'thumbnail_image'], 
  53             stream_url_hls 
= video_data
.get('stream_url_hls') 
  55                 formats
.extend(self
._extract
_m
3u8_formats
( 
  56                     stream_url_hls
, video_id
, 'mp4', 
  57                     entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False)) 
  59             stream_url_hds 
= video_data
.get('stream_url_hds') 
  61                 formats
.extend(self
._extract
_f
4m
_formats
( 
  62                     stream_url_hds 
+ '?hdcore=3.4.0', 
  63                     video_id
, f4m_id
='hds', fatal
=False)) 
  65             for video_version 
in video_data
.get('video_versions', []): 
  66                 video_version_url 
= video_version
.get('download_url') or video_version
.get('stream_url') 
  67                 if not video_version_url
: 
  70                     'url': video_version_url
, 
  71                     'width': int_or_none(video_version
.get('width')), 
  72                     'height': int_or_none(video_version
.get('height')), 
  73                     'abr': int_or_none(video_version
.get('audio_bitrate')), 
  74                     'vbr': int_or_none(video_version
.get('video_bitrate')), 
  76                 bitrate 
= self
._search
_regex
(r
'(\d+)k', video_version_url
, 'bitrate', default
=None) 
  79                         'format_id': 'http-%s' % bitrate
, 
  82             self
._sort
_formats
(formats
) 
  86                 'title': video_data
['title'], 
  87                 'description': video_data
.get('subtitle'), 
  88                 'thumbnail': video_data
.get('thumbnail_image', {}).get('file'), 
  89                 'timestamp': parse_iso8601(video_data
.get('publication_date')), 
  90                 'duration': int_or_none(video_data
.get('duration')), 
  91                 'view_count': int_or_none(video_data
.get('view_count')),