]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/webofstories.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  13 class WebOfStoriesIE(InfoExtractor
): 
  14     _VALID_URL 
= r
'https?://(?:www\.)?webofstories\.com/play/(?:[^/]+/)?(?P<id>[0-9]+)' 
  15     _VIDEO_DOMAIN 
= 'http://eu-mobile.webofstories.com/' 
  16     _GREAT_LIFE_STREAMER 
= 'rtmp://eu-cdn1.webofstories.com/cfx/st/' 
  17     _USER_STREAMER 
= 'rtmp://eu-users.webofstories.com/cfx/st/' 
  19         'url': 'http://www.webofstories.com/play/hans.bethe/71', 
  20         'md5': '373e4dd915f60cfe3116322642ddf364', 
  24             'title': 'The temperature of the sun', 
  25             'thumbnail': r
're:^https?://.*\.jpg$', 
  26             'description': 'Hans Bethe talks about calculating the temperature of the sun', 
  30         'url': 'http://www.webofstories.com/play/55908', 
  31         'md5': '2985a698e1fe3211022422c4b5ed962c', 
  35             'title': 'The story of Gemmata obscuriglobus', 
  36             'thumbnail': r
're:^https?://.*\.jpg$', 
  37             'description': 'Planctomycete talks about The story of Gemmata obscuriglobus', 
  42         # malformed og:title meta 
  43         'url': 'http://www.webofstories.com/play/54215?o=MS', 
  47             'title': '"A Leg to Stand On"', 
  48             'thumbnail': r
're:^https?://.*\.jpg$', 
  49             'description': 'Oliver Sacks talks about the death and resurrection of a limb', 
  53             'skip_download': True, 
  57     def _real_extract(self
, url
): 
  58         video_id 
= self
._match
_id
(url
) 
  60         webpage 
= self
._download
_webpage
(url
, video_id
) 
  61         # Sometimes og:title meta is malformed 
  62         title 
= self
._og
_search
_title
(webpage
, default
=None) or self
._html
_search
_regex
( 
  63             r
'(?s)<strong>Title:\s*</strong>(.+?)<', webpage
, 'title') 
  64         description 
= self
._html
_search
_meta
('description', webpage
) 
  65         thumbnail 
= self
._og
_search
_thumbnail
(webpage
) 
  67         embed_params 
= [s
.strip(" \r\n\t'") for s 
in self
._search
_regex
( 
  68             r
'(?s)\$\("#embedCode"\).html\(getEmbedCode\((.*?)\)', 
  69             webpage
, 'embed params').split(',')] 
  72             _
, speaker_id
, story_id
, story_duration
, 
  73             speaker_type
, great_life
, _thumbnail
, _has_subtitles
, 
  74             story_filename
, _story_order
) = embed_params
 
  76         is_great_life_series 
= great_life 
== 'true' 
  77         duration 
= int_or_none(story_duration
) 
  79         # URL building, see: http://www.webofstories.com/scripts/player.js 
  81         if speaker_type
.lower() == 'ms': 
  82             ms_prefix 
= 'mini_sites/' 
  84         if is_great_life_series
: 
  85             mp4_url 
= '{0:}lives/{1:}/{2:}.mp4'.format( 
  86                 self
._VIDEO
_DOMAIN
, speaker_id
, story_filename
) 
  88             streamer 
= self
._GREAT
_LIFE
_STREAMER
 
  89             play_path 
= 'stories/{0:}/{1:}'.format( 
  90                 speaker_id
, story_filename
) 
  92             mp4_url 
= '{0:}{1:}{2:}/{3:}.mp4'.format( 
  93                 self
._VIDEO
_DOMAIN
, ms_prefix
, speaker_id
, story_filename
) 
  95             streamer 
= self
._USER
_STREAMER
 
  96             play_path 
= 'mp4:{0:}{1:}/{2}.mp4'.format( 
  97                 ms_prefix
, speaker_id
, story_filename
) 
 100             'format_id': 'mp4_sd', 
 103             'format_id': 'rtmp_sd', 
 107             'play_path': play_path
, 
 110         self
._sort
_formats
(formats
) 
 116             'thumbnail': thumbnail
, 
 117             'description': description
, 
 118             'duration': duration
, 
 122 class WebOfStoriesPlaylistIE(InfoExtractor
): 
 123     _VALID_URL 
= r
'https?://(?:www\.)?webofstories\.com/playAll/(?P<id>[^/]+)' 
 125         'url': 'http://www.webofstories.com/playAll/donald.knuth', 
 127             'id': 'donald.knuth', 
 128             'title': 'Donald Knuth (Scientist)', 
 130         'playlist_mincount': 97, 
 133     def _real_extract(self
, url
): 
 134         playlist_id 
= self
._match
_id
(url
) 
 136         webpage 
= self
._download
_webpage
(url
, playlist_id
) 
 140                 'http://www.webofstories.com/play/%s' % video_id
, 
 141                 'WebOfStories', video_id
=video_id
) 
 142             for video_id 
in orderedSet(re
.findall(r
'\bid=["\']td_(\d
+)', webpage)) 
 145         title = self._search_regex( 
 146             r'<div 
id="speakerName">\s
*<span
>([^
<]+)</span
>', 
 147             webpage, 'speaker
', default=None) 
 149             field = self._search_regex( 
 150                 r'<span 
id="primaryField">([^
<]+)</span
>', 
 151                 webpage, 'field
', default=None) 
 153                 title += ' (%s)' % field 
 156             title = self._search_regex( 
 157                 r'<title
>Play\s
+all\s
+stories\s
*-\s
*([^
<]+)\s
*-\s
*Web\s
+of\s
+Stories
</title
>', 
 160         return self.playlist_result(entries, playlist_id, title)