]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/webofstories.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..utils
import int_or_none
10 class WebOfStoriesIE(InfoExtractor
):
11 _VALID_URL
= r
'https?://(?:www\.)?webofstories\.com/play/(?:[^/]+/)?(?P<id>[0-9]+)'
12 _VIDEO_DOMAIN
= 'http://eu-mobile.webofstories.com/'
13 _GREAT_LIFE_STREAMER
= 'rtmp://eu-cdn1.webofstories.com/cfx/st/'
14 _USER_STREAMER
= 'rtmp://eu-users.webofstories.com/cfx/st/'
16 'url': 'http://www.webofstories.com/play/hans.bethe/71',
17 'md5': '373e4dd915f60cfe3116322642ddf364',
21 'title': 'The temperature of the sun',
22 'thumbnail': r
're:^https?://.*\.jpg$',
23 'description': 'Hans Bethe talks about calculating the temperature of the sun',
27 'url': 'http://www.webofstories.com/play/55908',
28 'md5': '2985a698e1fe3211022422c4b5ed962c',
32 'title': 'The story of Gemmata obscuriglobus',
33 'thumbnail': r
're:^https?://.*\.jpg$',
34 'description': 'Planctomycete talks about The story of Gemmata obscuriglobus',
39 # malformed og:title meta
40 'url': 'http://www.webofstories.com/play/54215?o=MS',
44 'title': '"A Leg to Stand On"',
45 'thumbnail': r
're:^https?://.*\.jpg$',
46 'description': 'Oliver Sacks talks about the death and resurrection of a limb',
50 'skip_download': True,
54 def _real_extract(self
, url
):
55 video_id
= self
._match
_id
(url
)
57 webpage
= self
._download
_webpage
(url
, video_id
)
58 # Sometimes og:title meta is malformed
59 title
= self
._og
_search
_title
(webpage
, default
=None) or self
._html
_search
_regex
(
60 r
'(?s)<strong>Title:\s*</strong>(.+?)<', webpage
, 'title')
61 description
= self
._html
_search
_meta
('description', webpage
)
62 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
64 embed_params
= [s
.strip(" \r\n\t'") for s
in self
._search
_regex
(
65 r
'(?s)\$\("#embedCode"\).html\(getEmbedCode\((.*?)\)',
66 webpage
, 'embed params').split(',')]
69 _
, speaker_id
, story_id
, story_duration
,
70 speaker_type
, great_life
, _thumbnail
, _has_subtitles
,
71 story_filename
, _story_order
) = embed_params
73 is_great_life_series
= great_life
== 'true'
74 duration
= int_or_none(story_duration
)
76 # URL building, see: http://www.webofstories.com/scripts/player.js
78 if speaker_type
.lower() == 'ms':
79 ms_prefix
= 'mini_sites/'
81 if is_great_life_series
:
82 mp4_url
= '{0:}lives/{1:}/{2:}.mp4'.format(
83 self
._VIDEO
_DOMAIN
, speaker_id
, story_filename
)
85 streamer
= self
._GREAT
_LIFE
_STREAMER
86 play_path
= 'stories/{0:}/{1:}'.format(
87 speaker_id
, story_filename
)
89 mp4_url
= '{0:}{1:}{2:}/{3:}.mp4'.format(
90 self
._VIDEO
_DOMAIN
, ms_prefix
, speaker_id
, story_filename
)
92 streamer
= self
._USER
_STREAMER
93 play_path
= 'mp4:{0:}{1:}/{2}.mp4'.format(
94 ms_prefix
, speaker_id
, story_filename
)
97 'format_id': 'mp4_sd',
100 'format_id': 'rtmp_sd',
104 'play_path': play_path
,
107 self
._sort
_formats
(formats
)
113 'thumbnail': thumbnail
,
114 'description': description
,
115 'duration': duration
,
119 class WebOfStoriesPlaylistIE(InfoExtractor
):
120 _VALID_URL
= r
'https?://(?:www\.)?webofstories\.com/playAll/(?P<id>[^/]+)'
122 'url': 'http://www.webofstories.com/playAll/donald.knuth',
124 'id': 'donald.knuth',
125 'title': 'Donald Knuth (Scientist)',
127 'playlist_mincount': 97,
130 def _real_extract(self
, url
):
131 playlist_id
= self
._match
_id
(url
)
133 webpage
= self
._download
_webpage
(url
, playlist_id
)
136 self
.url_result('http://www.webofstories.com/play/%s' % video_number
, 'WebOfStories')
137 for video_number
in set(re
.findall(r
'href="/playAll/%s\?sId=(\d+)"' % playlist_id
, webpage
))
140 title
= self
._search
_regex
(
141 r
'<div id="speakerName">\s*<span>([^<]+)</span>',
142 webpage
, 'speaker', default
=None)
144 field
= self
._search
_regex
(
145 r
'<span id="primaryField">([^<]+)</span>',
146 webpage
, 'field', default
=None)
148 title
+= ' (%s)' % field
151 title
= self
._search
_regex
(
152 r
'<title>Play\s+all\s+stories\s*-\s*([^<]+)\s*-\s*Web\s+of\s+Stories</title>',
155 return self
.playlist_result(entries
, playlist_id
, title
)