]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/webofstories.py
Prepare for release.
[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 story_filename = self._search_regex(
49 r'\.storyFileName\("([^"]+)"\)', webpage, 'story filename')
50 speaker_id = self._search_regex(
51 r'\.speakerId\("([^"]+)"\)', webpage, 'speaker ID')
52 story_id = self._search_regex(
53 r'\.storyId\((\d+)\)', webpage, 'story ID')
54 speaker_type = self._search_regex(
55 r'\.speakerType\("([^"]+)"\)', webpage, 'speaker type')
56 great_life = self._search_regex(
57 r'isGreatLifeStory\s*=\s*(true|false)', webpage, 'great life story')
58 is_great_life_series = great_life == 'true'
59 duration = int_or_none(self._search_regex(
60 r'\.duration\((\d+)\)', webpage, 'duration', fatal=False))
61
62 # URL building, see: http://www.webofstories.com/scripts/player.js
63 ms_prefix = ''
64 if speaker_type.lower() == 'ms':
65 ms_prefix = 'mini_sites/'
66
67 if is_great_life_series:
68 mp4_url = '{0:}lives/{1:}/{2:}.mp4'.format(
69 self._VIDEO_DOMAIN, speaker_id, story_filename)
70 rtmp_ext = 'flv'
71 streamer = self._GREAT_LIFE_STREAMER
72 play_path = 'stories/{0:}/{1:}'.format(
73 speaker_id, story_filename)
74 else:
75 mp4_url = '{0:}{1:}{2:}/{3:}.mp4'.format(
76 self._VIDEO_DOMAIN, ms_prefix, speaker_id, story_filename)
77 rtmp_ext = 'mp4'
78 streamer = self._USER_STREAMER
79 play_path = 'mp4:{0:}{1:}/{2}.mp4'.format(
80 ms_prefix, speaker_id, story_filename)
81
82 formats = [{
83 'format_id': 'mp4_sd',
84 'url': mp4_url,
85 }, {
86 'format_id': 'rtmp_sd',
87 'page_url': url,
88 'url': streamer,
89 'ext': rtmp_ext,
90 'play_path': play_path,
91 }]
92
93 self._sort_formats(formats)
94
95 return {
96 'id': story_id,
97 'title': title,
98 'formats': formats,
99 'thumbnail': thumbnail,
100 'description': description,
101 'duration': duration,
102 }