]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kanalplay.py
4597d1b961a0fcae8137d3ec919fc2ce6ac31777
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  10     srt_subtitles_timecode
, 
  14 class KanalPlayIE(InfoExtractor
): 
  15     IE_DESC 
= 'Kanal 5/9/11 Play' 
  16     _VALID_URL 
= r
'https?://(?:www\.)?kanal(?P<channel_id>5|9|11)play\.se/(?:#!/)?(?:play/)?program/\d+/video/(?P<id>\d+)' 
  18         'url': 'http://www.kanal5play.se/#!/play/program/3060212363/video/3270012277', 
  22             'title': 'Saknar både dusch och avlopp', 
  23             'description': 'md5:6023a95832a06059832ae93bc3c7efb7', 
  28             'skip_download': True, 
  31         'url': 'http://www.kanal9play.se/#!/play/program/335032/video/246042', 
  32         'only_matching': True, 
  34         'url': 'http://www.kanal11play.se/#!/play/program/232835958/video/367135199', 
  35         'only_matching': True, 
  38     def _fix_subtitles(self
, subs
): 
  39         return '\r\n\r\n'.join( 
  40             '%s\r\n%s --> %s\r\n%s' 
  43                 srt_subtitles_timecode(item
['startMillis'] / 1000.0), 
  44                 srt_subtitles_timecode(item
['endMillis'] / 1000.0), 
  46             ) for num
, item 
in enumerate(subs
, 1)) 
  48     def _get_subtitles(self
, channel_id
, video_id
): 
  49         subs 
= self
._download
_json
( 
  50             'http://www.kanal%splay.se/api/subtitles/%s' % (channel_id
, video_id
), 
  51             video_id
, 'Downloading subtitles JSON', fatal
=False) 
  52         return {'se': [{'ext': 'srt', 'data': self
._fix
_subtitles
(subs
)}]} if subs 
else {} 
  54     def _real_extract(self
, url
): 
  55         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  56         video_id 
= mobj
.group('id') 
  57         channel_id 
= mobj
.group('channel_id') 
  59         video 
= self
._download
_json
( 
  60             'http://www.kanal%splay.se/api/getVideo?format=FLASH&videoId=%s' % (channel_id
, video_id
), 
  63         reasons_for_no_streams 
= video
.get('reasonsForNoStreams') 
  64         if reasons_for_no_streams
: 
  66                 '%s returned error: %s' % (self
.IE_NAME
, '\n'.join(reasons_for_no_streams
)), 
  69         title 
= video
['title'] 
  70         description 
= video
.get('description') 
  71         duration 
= float_or_none(video
.get('length'), 1000) 
  72         thumbnail 
= video
.get('posterUrl') 
  74         stream_base_url 
= video
['streamBaseUrl'] 
  77             'url': stream_base_url
, 
  78             'play_path': stream
['source'], 
  80             'tbr': float_or_none(stream
.get('bitrate'), 1000), 
  81             'rtmp_real_time': True, 
  82         } for stream 
in video
['streams']] 
  83         self
._sort
_formats
(formats
) 
  86         if video
.get('hasSubtitle'): 
  87             subtitles 
= self
.extract_subtitles(channel_id
, video_id
) 
  92             'description': description
, 
  93             'thumbnail': thumbnail
, 
  96             'subtitles': subtitles
,