]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/eagleplatform.py
113a4966fb3c444f5759e617e36b293ee88e6872
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_HTTPError
 
  15 class EaglePlatformIE(InfoExtractor
): 
  18                         eagleplatform:(?P<custom_host>[^/]+):| 
  19                         https?://(?P<host>.+?\.media\.eagleplatform\.com)/index/player\?.*\brecord_id= 
  24         # http://lenta.ru/news/2015/03/06/navalny/ 
  25         'url': 'http://lentaru.media.eagleplatform.com/index/player?player=new&record_id=227304&player_template_id=5201', 
  26         # Not checking MD5 as sometimes the direct HTTP link results in 404 and HLS is used 
  30             'title': 'Навальный вышел на свободу', 
  31             'description': 'md5:d97861ac9ae77377f3f20eaf9d04b4f5', 
  32             'thumbnail': 're:^https?://.*\.jpg$', 
  38         # http://muz-tv.ru/play/7129/ 
  39         # http://media.clipyou.ru/index/player?record_id=12820&width=730&height=415&autoplay=true 
  40         'url': 'eagleplatform:media.clipyou.ru:12820', 
  41         'md5': '358597369cf8ba56675c1df15e7af624', 
  45             'title': "'O Sole Mio", 
  46             'thumbnail': 're:^https?://.*\.jpg$', 
  50         'skip': 'Georestricted', 
  54     def _handle_error(response
): 
  55         status 
= int_or_none(response
.get('status', 200)) 
  57             raise ExtractorError(' '.join(response
['errors']), expected
=True) 
  59     def _download_json(self
, url_or_request
, video_id
, note
='Downloading JSON metadata'): 
  61             response 
= super(EaglePlatformIE
, self
)._download
_json
(url_or_request
, video_id
, note
) 
  62         except ExtractorError 
as ee
: 
  63             if isinstance(ee
.cause
, compat_HTTPError
): 
  64                 response 
= self
._parse
_json
(ee
.cause
.read().decode('utf-8'), video_id
) 
  65                 self
._handle
_error
(response
) 
  69     def _get_video_url(self
, url_or_request
, video_id
, note
='Downloading JSON metadata'): 
  70         return self
._download
_json
(url_or_request
, video_id
, note
)['data'][0] 
  72     def _real_extract(self
, url
): 
  73         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  74         host
, video_id 
= mobj
.group('custom_host') or mobj
.group('host'), mobj
.group('id') 
  76         player_data 
= self
._download
_json
( 
  77             'http://%s/api/player_data?id=%s' % (host
, video_id
), video_id
) 
  79         media 
= player_data
['data']['playlist']['viewports'][0]['medialist'][0] 
  81         title 
= media
['title'] 
  82         description 
= media
.get('description') 
  83         thumbnail 
= self
._proto
_relative
_url
(media
.get('snapshot'), 'http:') 
  84         duration 
= int_or_none(media
.get('duration')) 
  85         view_count 
= int_or_none(media
.get('views')) 
  87         age_restriction 
= media
.get('age_restriction') 
  90             age_limit 
= 0 if age_restriction 
== 'allow_all' else 18 
  92         secure_m3u8 
= self
._proto
_relative
_url
(media
['sources']['secure_m3u8']['auto'], 'http:') 
  96         m3u8_url 
= self
._get
_video
_url
(secure_m3u8
, video_id
, 'Downloading m3u8 JSON') 
  97         m3u8_formats 
= self
._extract
_m
3u8_formats
( 
  99             'mp4', entry_protocol
='m3u8_native', m3u8_id
='hls') 
 100         formats
.extend(m3u8_formats
) 
 102         mp4_url 
= self
._get
_video
_url
( 
 103             # Secure mp4 URL is constructed according to Player.prototype.mp4 from 
 104             # http://lentaru.media.eagleplatform.com/player/player.js 
 105             re
.sub(r
'm3u8|hlsvod|hls|f4m', 'mp4', secure_m3u8
), 
 106             video_id
, 'Downloading mp4 JSON') 
 107         mp4_url_basename 
= url_basename(mp4_url
) 
 108         for m3u8_format 
in m3u8_formats
: 
 109             mobj 
= re
.search('/([^/]+)/index\.m3u8', m3u8_format
['url']) 
 111                 http_format 
= m3u8_format
.copy() 
 112                 video_url 
= mp4_url
.replace(mp4_url_basename
, mobj
.group(1)) 
 113                 if not self
._is
_valid
_url
(video_url
, video_id
): 
 117                     'format_id': m3u8_format
['format_id'].replace('hls', 'http'), 
 120                 formats
.append(http_format
) 
 122         self
._sort
_formats
(formats
) 
 127             'description': description
, 
 128             'thumbnail': thumbnail
, 
 129             'duration': duration
, 
 130             'view_count': view_count
, 
 131             'age_limit': age_limit
,