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.

100 lines
3.5 KiB

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