]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/limelight.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  14 class LimelightBaseIE(InfoExtractor
): 
  15     _PLAYLIST_SERVICE_URL 
= 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s' 
  16     _API_URL 
= 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json' 
  18     def _call_playlist_service(self
, item_id
, method
, fatal
=True): 
  19         return self
._download
_json
( 
  20             self
._PLAYLIST
_SERVICE
_URL 
% (self
._PLAYLIST
_SERVICE
_PATH
, item_id
, method
), 
  21             item_id
, 'Downloading PlaylistService %s JSON' % method
, fatal
=fatal
) 
  23     def _call_api(self
, organization_id
, item_id
, method
): 
  24         return self
._download
_json
( 
  25             self
._API
_URL 
% (organization_id
, self
._API
_PATH
, item_id
, method
), 
  26             item_id
, 'Downloading API %s JSON' % method
) 
  28     def _extract(self
, item_id
, pc_method
, mobile_method
, meta_method
): 
  29         pc 
= self
._call
_playlist
_service
(item_id
, pc_method
) 
  30         metadata 
= self
._call
_api
(pc
['orgId'], item_id
, meta_method
) 
  31         mobile 
= self
._call
_playlist
_service
(item_id
, mobile_method
, fatal
=False) 
  32         return pc
, mobile
, metadata
 
  34     def _extract_info(self
, streams
, mobile_urls
, properties
): 
  35         video_id 
= properties
['media_id'] 
  38         for stream 
in streams
: 
  39             stream_url 
= stream
.get('url') 
  42             if '.f4m' in stream_url
: 
  43                 formats
.extend(self
._extract
_f
4m
_formats
( 
  44                     stream_url
, video_id
, fatal
=False)) 
  48                     'abr': float_or_none(stream
.get('audioBitRate')), 
  49                     'vbr': float_or_none(stream
.get('videoBitRate')), 
  50                     'fps': float_or_none(stream
.get('videoFrameRate')), 
  51                     'width': int_or_none(stream
.get('videoWidthInPixels')), 
  52                     'height': int_or_none(stream
.get('videoHeightInPixels')), 
  53                     'ext': determine_ext(stream_url
) 
  55                 rtmp 
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', stream_url
) 
  58                     if stream
.get('videoBitRate'): 
  59                         format_id 
+= '-%d' % int_or_none(stream
['videoBitRate']) 
  61                         'url': rtmp
.group('url'), 
  62                         'play_path': rtmp
.group('playpath'), 
  63                         'app': rtmp
.group('app'), 
  65                         'format_id': format_id
, 
  69         for mobile_url 
in mobile_urls
: 
  70             media_url 
= mobile_url
.get('mobileUrl') 
  73             format_id 
= mobile_url
.get('targetMediaPlatform') 
  74             if determine_ext(media_url
) == 'm3u8': 
  75                 formats
.extend(self
._extract
_m
3u8_formats
( 
  76                     media_url
, video_id
, 'mp4', 'm3u8_native', 
  77                     m3u8_id
=format_id
, fatal
=False)) 
  81                     'format_id': format_id
, 
  85         self
._sort
_formats
(formats
) 
  87         title 
= properties
['title'] 
  88         description 
= properties
.get('description') 
  89         timestamp 
= int_or_none(properties
.get('publish_date') or properties
.get('create_date')) 
  90         duration 
= float_or_none(properties
.get('duration_in_milliseconds'), 1000) 
  91         filesize 
= int_or_none(properties
.get('total_storage_in_bytes')) 
  92         categories 
= [properties
.get('category')] 
  93         tags 
= properties
.get('tags', []) 
  95             'url': thumbnail
['url'], 
  96             'width': int_or_none(thumbnail
.get('width')), 
  97             'height': int_or_none(thumbnail
.get('height')), 
  98         } for thumbnail 
in properties
.get('thumbnails', []) if thumbnail
.get('url')] 
 101         for caption 
in properties
.get('captions', []): 
 102             lang 
= caption
.get('language_code') 
 103             subtitles_url 
= caption
.get('url') 
 104             if lang 
and subtitles_url
: 
 105                 subtitles
.setdefault(lang
, []).append({ 
 106                     'url': subtitles_url
, 
 108         closed_captions_url 
= properties
.get('closed_captions_url') 
 109         if closed_captions_url
: 
 110             subtitles
.setdefault('en', []).append({ 
 111                 'url': closed_captions_url
, 
 118             'description': description
, 
 120             'timestamp': timestamp
, 
 121             'duration': duration
, 
 122             'filesize': filesize
, 
 123             'categories': categories
, 
 125             'thumbnails': thumbnails
, 
 126             'subtitles': subtitles
, 
 130 class LimelightMediaIE(LimelightBaseIE
): 
 131     IE_NAME 
= 'limelight' 
 132     _VALID_URL 
= r
'''(?x) 
 137                                     link\.videoplatform\.limelight\.com/media/| 
 138                                     assets\.delvenetworks\.com/player/loader\.swf 
 145         'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86', 
 147             'id': '3ffd040b522b4485b6d84effc750cd86', 
 149             'title': 'HaP and the HB Prince Trailer', 
 150             'description': 'md5:8005b944181778e313d95c1237ddb640', 
 151             'thumbnail': 're:^https?://.*\.jpeg$', 
 153             'timestamp': 1244136834, 
 154             'upload_date': '20090604', 
 158             'skip_download': True, 
 161         # video with subtitles 
 162         'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335', 
 164             'id': 'a3e00274d4564ec4a9b29b9466432335', 
 166             'title': '3Play Media Overview Video', 
 168             'thumbnail': 're:^https?://.*\.jpeg$', 
 170             'timestamp': 1338929955, 
 171             'upload_date': '20120605', 
 172             'subtitles': 'mincount:9', 
 176             'skip_download': True, 
 179         'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452', 
 180         'only_matching': True, 
 182     _PLAYLIST_SERVICE_PATH 
= 'media' 
 185     def _real_extract(self
, url
): 
 186         video_id 
= self
._match
_id
(url
) 
 188         pc
, mobile
, metadata 
= self
._extract
( 
 189             video_id
, 'getPlaylistByMediaId', 'getMobilePlaylistByMediaId', 'properties') 
 191         return self
._extract
_info
( 
 192             pc
['playlistItems'][0].get('streams', []), 
 193             mobile
['mediaList'][0].get('mobileUrls', []) if mobile 
else [], 
 197 class LimelightChannelIE(LimelightBaseIE
): 
 198     IE_NAME 
= 'limelight:channel' 
 199     _VALID_URL 
= r
'''(?x) 
 204                                     link\.videoplatform\.limelight\.com/media/| 
 205                                     assets\.delvenetworks\.com/player/loader\.swf 
 212         'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082', 
 214             'id': 'ab6a524c379342f9b23642917020c082', 
 215             'title': 'Javascript Sample Code', 
 217         'playlist_mincount': 3, 
 219         'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082', 
 220         'only_matching': True, 
 222     _PLAYLIST_SERVICE_PATH 
= 'channel' 
 223     _API_PATH 
= 'channels' 
 225     def _real_extract(self
, url
): 
 226         channel_id 
= self
._match
_id
(url
) 
 228         pc
, mobile
, medias 
= self
._extract
( 
 229             channel_id
, 'getPlaylistByChannelId', 
 230             'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1', 'media') 
 234                 pc
['playlistItems'][i
].get('streams', []), 
 235                 mobile
['mediaList'][i
].get('mobileUrls', []) if mobile 
else [], 
 236                 medias
['media_list'][i
]) 
 237             for i 
in range(len(medias
['media_list']))] 
 239         return self
.playlist_result(entries
, channel_id
, pc
['title']) 
 242 class LimelightChannelListIE(LimelightBaseIE
): 
 243     IE_NAME 
= 'limelight:channel_list' 
 244     _VALID_URL 
= r
'''(?x) 
 246                             limelight:channel_list:| 
 249                                     link\.videoplatform\.limelight\.com/media/| 
 250                                     assets\.delvenetworks\.com/player/loader\.swf 
 252                                 \?.*?\bchannelListId= 
 257         'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b', 
 259             'id': '301b117890c4465c8179ede21fd92e2b', 
 260             'title': 'Website - Hero Player', 
 262         'playlist_mincount': 2, 
 264         'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b', 
 265         'only_matching': True, 
 267     _PLAYLIST_SERVICE_PATH 
= 'channel_list' 
 269     def _real_extract(self
, url
): 
 270         channel_list_id 
= self
._match
_id
(url
) 
 272         channel_list 
= self
._call
_playlist
_service
(channel_list_id
, 'getMobileChannelListById') 
 275             self
.url_result('limelight:channel:%s' % channel
['id'], 'LimelightChannel') 
 276             for channel 
in channel_list
['channelList']] 
 278         return self
.playlist_result(entries
, channel_list_id
, channel_list
['title'])