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.

141 lines
4.8 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. {
  13. 'url': 'http://www.webofstories.com/play/hans.bethe/71',
  14. 'md5': '373e4dd915f60cfe3116322642ddf364',
  15. 'info_dict': {
  16. 'id': '4536',
  17. 'ext': 'mp4',
  18. 'title': 'The temperature of the sun',
  19. 'thumbnail': 're:^https?://.*\.jpg$',
  20. 'description': 'Hans Bethe talks about calculating the temperature of the sun',
  21. 'duration': 238,
  22. }
  23. },
  24. {
  25. 'url': 'http://www.webofstories.com/play/55908',
  26. 'md5': '2985a698e1fe3211022422c4b5ed962c',
  27. 'info_dict': {
  28. 'id': '55908',
  29. 'ext': 'mp4',
  30. 'title': 'The story of Gemmata obscuriglobus',
  31. 'thumbnail': 're:^https?://.*\.jpg$',
  32. 'description': 'Planctomycete talks about The story of Gemmata obscuriglobus',
  33. 'duration': 169,
  34. }
  35. },
  36. ]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. title = self._og_search_title(webpage)
  41. description = self._html_search_meta('description', webpage)
  42. thumbnail = self._og_search_thumbnail(webpage)
  43. embed_params = [s.strip(" \r\n\t'") for s in self._search_regex(
  44. r'(?s)\$\("#embedCode"\).html\(getEmbedCode\((.*?)\)',
  45. webpage, 'embed params').split(',')]
  46. (
  47. _, speaker_id, story_id, story_duration,
  48. speaker_type, great_life, _thumbnail, _has_subtitles,
  49. story_filename, _story_order) = embed_params
  50. is_great_life_series = great_life == 'true'
  51. duration = int_or_none(story_duration)
  52. # URL building, see: http://www.webofstories.com/scripts/player.js
  53. ms_prefix = ''
  54. if speaker_type.lower() == 'ms':
  55. ms_prefix = 'mini_sites/'
  56. if is_great_life_series:
  57. mp4_url = '{0:}lives/{1:}/{2:}.mp4'.format(
  58. self._VIDEO_DOMAIN, speaker_id, story_filename)
  59. rtmp_ext = 'flv'
  60. streamer = self._GREAT_LIFE_STREAMER
  61. play_path = 'stories/{0:}/{1:}'.format(
  62. speaker_id, story_filename)
  63. else:
  64. mp4_url = '{0:}{1:}{2:}/{3:}.mp4'.format(
  65. self._VIDEO_DOMAIN, ms_prefix, speaker_id, story_filename)
  66. rtmp_ext = 'mp4'
  67. streamer = self._USER_STREAMER
  68. play_path = 'mp4:{0:}{1:}/{2}.mp4'.format(
  69. ms_prefix, speaker_id, story_filename)
  70. formats = [{
  71. 'format_id': 'mp4_sd',
  72. 'url': mp4_url,
  73. }, {
  74. 'format_id': 'rtmp_sd',
  75. 'page_url': url,
  76. 'url': streamer,
  77. 'ext': rtmp_ext,
  78. 'play_path': play_path,
  79. }]
  80. self._sort_formats(formats)
  81. return {
  82. 'id': story_id,
  83. 'title': title,
  84. 'formats': formats,
  85. 'thumbnail': thumbnail,
  86. 'description': description,
  87. 'duration': duration,
  88. }
  89. class WebOfStoriesPlaylistIE(InfoExtractor):
  90. _VALID_URL = r'https?://(?:www\.)?webofstories\.com/playAll/(?P<id>[^/]+)'
  91. _TEST = {
  92. 'url': 'http://www.webofstories.com/playAll/donald.knuth',
  93. 'info_dict': {
  94. 'id': 'donald.knuth',
  95. 'title': 'Donald Knuth (Scientist)',
  96. },
  97. 'playlist_mincount': 97,
  98. }
  99. def _real_extract(self, url):
  100. playlist_id = self._match_id(url)
  101. webpage = self._download_webpage(url, playlist_id)
  102. entries = [
  103. self.url_result('http://www.webofstories.com/play/%s' % video_number, 'WebOfStories')
  104. for video_number in set(re.findall('href="/playAll/%s\?sId=(\d+)"' % playlist_id, webpage))
  105. ]
  106. title = self._search_regex(
  107. r'<div id="speakerName">\s*<span>([^<]+)</span>',
  108. webpage, 'speaker', default=None)
  109. if title:
  110. field = self._search_regex(
  111. r'<span id="primaryField">([^<]+)</span>',
  112. webpage, 'field', default=None)
  113. if field:
  114. title += ' (%s)' % field
  115. if not title:
  116. title = self._search_regex(
  117. r'<title>Play\s+all\s+stories\s*-\s*([^<]+)\s*-\s*Web\s+of\s+Stories</title>',
  118. webpage, 'title')
  119. return self.playlist_result(entries, playlist_id, title)