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.

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