You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class WebOfStoriesIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?webofstories\.com/play/(?:[^/]+/)?(?P<id>[0-9]+)'
  8. _VIDEO_DOMAIN = 'http://eu-mobile.webofstories.com/'
  9. _GREAT_LIFE_STREAMER = 'rtmp://eu-cdn1.webofstories.com/cfx/st/'
  10. _USER_STREAMER = 'rtmp://eu-users.webofstories.com/cfx/st/'
  11. _TESTS = [{
  12. 'url': 'http://www.webofstories.com/play/hans.bethe/71',
  13. 'md5': '373e4dd915f60cfe3116322642ddf364',
  14. 'info_dict': {
  15. 'id': '4536',
  16. 'ext': 'mp4',
  17. 'title': 'The temperature of the sun',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'description': 'Hans Bethe talks about calculating the temperature of the sun',
  20. 'duration': 238,
  21. }
  22. }, {
  23. 'url': 'http://www.webofstories.com/play/55908',
  24. 'md5': '2985a698e1fe3211022422c4b5ed962c',
  25. 'info_dict': {
  26. 'id': '55908',
  27. 'ext': 'mp4',
  28. 'title': 'The story of Gemmata obscuriglobus',
  29. 'thumbnail': r're:^https?://.*\.jpg$',
  30. 'description': 'Planctomycete talks about The story of Gemmata obscuriglobus',
  31. 'duration': 169,
  32. },
  33. 'skip': 'notfound',
  34. }, {
  35. # malformed og:title meta
  36. 'url': 'http://www.webofstories.com/play/54215?o=MS',
  37. 'info_dict': {
  38. 'id': '54215',
  39. 'ext': 'mp4',
  40. 'title': '"A Leg to Stand On"',
  41. 'thumbnail': r're:^https?://.*\.jpg$',
  42. 'description': 'Oliver Sacks talks about the death and resurrection of a limb',
  43. 'duration': 97,
  44. },
  45. 'params': {
  46. 'skip_download': True,
  47. },
  48. }]
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. webpage = self._download_webpage(url, video_id)
  52. # Sometimes og:title meta is malformed
  53. title = self._og_search_title(webpage, default=None) or self._html_search_regex(
  54. r'(?s)<strong>Title:\s*</strong>(.+?)<', webpage, 'title')
  55. description = self._html_search_meta('description', webpage)
  56. thumbnail = self._og_search_thumbnail(webpage)
  57. embed_params = [s.strip(" \r\n\t'") for s in self._search_regex(
  58. r'(?s)\$\("#embedCode"\).html\(getEmbedCode\((.*?)\)',
  59. webpage, 'embed params').split(',')]
  60. (
  61. _, speaker_id, story_id, story_duration,
  62. speaker_type, great_life, _thumbnail, _has_subtitles,
  63. story_filename, _story_order) = embed_params
  64. is_great_life_series = great_life == 'true'
  65. duration = int_or_none(story_duration)
  66. # URL building, see: http://www.webofstories.com/scripts/player.js
  67. ms_prefix = ''
  68. if speaker_type.lower() == 'ms':
  69. ms_prefix = 'mini_sites/'
  70. if is_great_life_series:
  71. mp4_url = '{0:}lives/{1:}/{2:}.mp4'.format(
  72. self._VIDEO_DOMAIN, speaker_id, story_filename)
  73. rtmp_ext = 'flv'
  74. streamer = self._GREAT_LIFE_STREAMER
  75. play_path = 'stories/{0:}/{1:}'.format(
  76. speaker_id, story_filename)
  77. else:
  78. mp4_url = '{0:}{1:}{2:}/{3:}.mp4'.format(
  79. self._VIDEO_DOMAIN, ms_prefix, speaker_id, story_filename)
  80. rtmp_ext = 'mp4'
  81. streamer = self._USER_STREAMER
  82. play_path = 'mp4:{0:}{1:}/{2}.mp4'.format(
  83. ms_prefix, speaker_id, story_filename)
  84. formats = [{
  85. 'format_id': 'mp4_sd',
  86. 'url': mp4_url,
  87. }, {
  88. 'format_id': 'rtmp_sd',
  89. 'page_url': url,
  90. 'url': streamer,
  91. 'ext': rtmp_ext,
  92. 'play_path': play_path,
  93. }]
  94. self._sort_formats(formats)
  95. return {
  96. 'id': story_id,
  97. 'title': title,
  98. 'formats': formats,
  99. 'thumbnail': thumbnail,
  100. 'description': description,
  101. 'duration': duration,
  102. }
  103. class WebOfStoriesPlaylistIE(InfoExtractor):
  104. _VALID_URL = r'https?://(?:www\.)?webofstories\.com/playAll/(?P<id>[^/]+)'
  105. _TEST = {
  106. 'url': 'http://www.webofstories.com/playAll/donald.knuth',
  107. 'info_dict': {
  108. 'id': 'donald.knuth',
  109. 'title': 'Donald Knuth (Scientist)',
  110. },
  111. 'playlist_mincount': 97,
  112. }
  113. def _real_extract(self, url):
  114. playlist_id = self._match_id(url)
  115. webpage = self._download_webpage(url, playlist_id)
  116. entries = [
  117. self.url_result('http://www.webofstories.com/play/%s' % video_number, 'WebOfStories')
  118. for video_number in set(re.findall(r'href="/playAll/%s\?sId=(\d+)"' % playlist_id, webpage))
  119. ]
  120. title = self._search_regex(
  121. r'<div id="speakerName">\s*<span>([^<]+)</span>',
  122. webpage, 'speaker', default=None)
  123. if title:
  124. field = self._search_regex(
  125. r'<span id="primaryField">([^<]+)</span>',
  126. webpage, 'field', default=None)
  127. if field:
  128. title += ' (%s)' % field
  129. if not title:
  130. title = self._search_regex(
  131. r'<title>Play\s+all\s+stories\s*-\s*([^<]+)\s*-\s*Web\s+of\s+Stories</title>',
  132. webpage, 'title')
  133. return self.playlist_result(entries, playlist_id, title)