webofstories.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. _TESTS = []
  92. def _real_extract(self, url):
  93. playlist_id = self._match_id(url)
  94. webpage = self._download_webpage(url, playlist_id)
  95. entries = [
  96. self.url_result('http://www.webofstories.com/play/%s' % video_number, 'WebOfStories')
  97. for video_number in set(re.findall('href="/playAll/%s\?sId=(\d+)"' % playlist_id, webpage))
  98. ]
  99. title = self._html_search_regex(
  100. r'<title>([^<]+)\s*-\s*Web\sof\sStories</title>', webpage, 'title')
  101. description = self._html_search_meta(
  102. 'description', webpage, 'description')
  103. return self.playlist_result(entries, playlist_id, title, description)