]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/webofstories.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / webofstories.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6
7
8 class WebOfStoriesIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?webofstories\.com/play/(?:[^/]+/)?(?P<id>[0-9]+)'
10 _VIDEO_DOMAIN = 'http://eu-mobile.webofstories.com/'
11 _GREAT_LIFE_STREAMER = 'rtmp://eu-cdn1.webofstories.com/cfx/st/'
12 _USER_STREAMER = 'rtmp://eu-users.webofstories.com/cfx/st/'
13 _TESTS = [
14 {
15 'url': 'http://www.webofstories.com/play/hans.bethe/71',
16 'md5': '373e4dd915f60cfe3116322642ddf364',
17 'info_dict': {
18 'id': '4536',
19 'ext': 'mp4',
20 'title': 'The temperature of the sun',
21 'thumbnail': 're:^https?://.*\.jpg$',
22 'description': 'Hans Bethe talks about calculating the temperature of the sun',
23 'duration': 238,
24 }
25 },
26 {
27 'url': 'http://www.webofstories.com/play/55908',
28 'md5': '2985a698e1fe3211022422c4b5ed962c',
29 'info_dict': {
30 'id': '55908',
31 'ext': 'mp4',
32 'title': 'The story of Gemmata obscuriglobus',
33 'thumbnail': 're:^https?://.*\.jpg$',
34 'description': 'Planctomycete talks about The story of Gemmata obscuriglobus',
35 'duration': 169,
36 }
37 },
38 ]
39
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
42
43 webpage = self._download_webpage(url, video_id)
44 title = self._og_search_title(webpage)
45 description = self._html_search_meta('description', webpage)
46 thumbnail = self._og_search_thumbnail(webpage)
47
48 embed_params = [s.strip(" \r\n\t'") for s in self._search_regex(
49 r'(?s)\$\("#embedCode"\).html\(getEmbedCode\((.*?)\)',
50 webpage, 'embed params').split(',')]
51
52 (
53 _, speaker_id, story_id, story_duration,
54 speaker_type, great_life, _thumbnail, _has_subtitles,
55 story_filename, _story_order) = embed_params
56
57 is_great_life_series = great_life == 'true'
58 duration = int_or_none(story_duration)
59
60 # URL building, see: http://www.webofstories.com/scripts/player.js
61 ms_prefix = ''
62 if speaker_type.lower() == 'ms':
63 ms_prefix = 'mini_sites/'
64
65 if is_great_life_series:
66 mp4_url = '{0:}lives/{1:}/{2:}.mp4'.format(
67 self._VIDEO_DOMAIN, speaker_id, story_filename)
68 rtmp_ext = 'flv'
69 streamer = self._GREAT_LIFE_STREAMER
70 play_path = 'stories/{0:}/{1:}'.format(
71 speaker_id, story_filename)
72 else:
73 mp4_url = '{0:}{1:}{2:}/{3:}.mp4'.format(
74 self._VIDEO_DOMAIN, ms_prefix, speaker_id, story_filename)
75 rtmp_ext = 'mp4'
76 streamer = self._USER_STREAMER
77 play_path = 'mp4:{0:}{1:}/{2}.mp4'.format(
78 ms_prefix, speaker_id, story_filename)
79
80 formats = [{
81 'format_id': 'mp4_sd',
82 'url': mp4_url,
83 }, {
84 'format_id': 'rtmp_sd',
85 'page_url': url,
86 'url': streamer,
87 'ext': rtmp_ext,
88 'play_path': play_path,
89 }]
90
91 self._sort_formats(formats)
92
93 return {
94 'id': story_id,
95 'title': title,
96 'formats': formats,
97 'thumbnail': thumbnail,
98 'description': description,
99 'duration': duration,
100 }