storyfire.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import functools
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. format_field,
  5. int_or_none,
  6. OnDemandPagedList,
  7. smuggle_url,
  8. )
  9. class StoryFireBaseIE(InfoExtractor):
  10. _VALID_URL_BASE = r'https?://(?:www\.)?storyfire\.com/'
  11. def _call_api(self, path, video_id, resource, query=None):
  12. return self._download_json(
  13. 'https://storyfire.com/app/%s/%s' % (path, video_id), video_id,
  14. 'Downloading %s JSON metadata' % resource, query=query)
  15. def _parse_video(self, video):
  16. title = video['title']
  17. vimeo_id = self._search_regex(
  18. r'https?://player\.vimeo\.com/external/(\d+)',
  19. video['vimeoVideoURL'], 'vimeo id')
  20. uploader_id = video.get('hostID')
  21. return {
  22. '_type': 'url_transparent',
  23. 'id': vimeo_id,
  24. 'title': title,
  25. 'description': video.get('description'),
  26. 'url': smuggle_url(
  27. 'https://player.vimeo.com/video/' + vimeo_id, {
  28. 'http_headers': {
  29. 'Referer': 'https://storyfire.com/',
  30. }
  31. }),
  32. 'thumbnail': video.get('storyImage'),
  33. 'view_count': int_or_none(video.get('views')),
  34. 'like_count': int_or_none(video.get('likesCount')),
  35. 'comment_count': int_or_none(video.get('commentsCount')),
  36. 'duration': int_or_none(video.get('videoDuration')),
  37. 'timestamp': int_or_none(video.get('publishDate')),
  38. 'uploader': video.get('username'),
  39. 'uploader_id': uploader_id,
  40. 'uploader_url': format_field(uploader_id, None, 'https://storyfire.com/user/%s/video'),
  41. 'episode_number': int_or_none(video.get('episodeNumber') or video.get('episode_number')),
  42. }
  43. class StoryFireIE(StoryFireBaseIE):
  44. _VALID_URL = StoryFireBaseIE._VALID_URL_BASE + r'video-details/(?P<id>[0-9a-f]{24})'
  45. _TEST = {
  46. 'url': 'https://storyfire.com/video-details/5df1d132b6378700117f9181',
  47. 'md5': 'caec54b9e4621186d6079c7ec100c1eb',
  48. 'info_dict': {
  49. 'id': '378954662',
  50. 'ext': 'mp4',
  51. 'title': 'Buzzfeed Teaches You About Memes',
  52. 'uploader_id': 'ntZAJFECERSgqHSxzonV5K2E89s1',
  53. 'timestamp': 1576129028,
  54. 'description': 'md5:0b4e28021548e144bed69bb7539e62ea',
  55. 'uploader': 'whang!',
  56. 'upload_date': '20191212',
  57. 'duration': 418,
  58. 'view_count': int,
  59. 'like_count': int,
  60. 'comment_count': int,
  61. },
  62. 'params': {
  63. 'skip_download': True,
  64. },
  65. 'expected_warnings': ['Unable to download JSON metadata']
  66. }
  67. def _real_extract(self, url):
  68. video_id = self._match_id(url)
  69. video = self._call_api(
  70. 'generic/video-detail', video_id, 'video')['video']
  71. return self._parse_video(video)
  72. class StoryFireUserIE(StoryFireBaseIE):
  73. _VALID_URL = StoryFireBaseIE._VALID_URL_BASE + r'user/(?P<id>[^/]+)/video'
  74. _TEST = {
  75. 'url': 'https://storyfire.com/user/UQ986nFxmAWIgnkZQ0ftVhq4nOk2/video',
  76. 'info_dict': {
  77. 'id': 'UQ986nFxmAWIgnkZQ0ftVhq4nOk2',
  78. },
  79. 'playlist_mincount': 151,
  80. }
  81. _PAGE_SIZE = 20
  82. def _fetch_page(self, user_id, page):
  83. videos = self._call_api(
  84. 'publicVideos', user_id, 'page %d' % (page + 1), {
  85. 'skip': page * self._PAGE_SIZE,
  86. })['videos']
  87. for video in videos:
  88. yield self._parse_video(video)
  89. def _real_extract(self, url):
  90. user_id = self._match_id(url)
  91. entries = OnDemandPagedList(functools.partial(
  92. self._fetch_page, user_id), self._PAGE_SIZE)
  93. return self.playlist_result(entries, user_id)
  94. class StoryFireSeriesIE(StoryFireBaseIE):
  95. _VALID_URL = StoryFireBaseIE._VALID_URL_BASE + r'write/series/stories/(?P<id>[^/?&#]+)'
  96. _TESTS = [{
  97. 'url': 'https://storyfire.com/write/series/stories/-Lq6MsuIHLODO6d2dDkr/',
  98. 'info_dict': {
  99. 'id': '-Lq6MsuIHLODO6d2dDkr',
  100. },
  101. 'playlist_mincount': 13,
  102. }, {
  103. 'url': 'https://storyfire.com/write/series/stories/the_mortal_one/',
  104. 'info_dict': {
  105. 'id': 'the_mortal_one',
  106. },
  107. 'playlist_count': 0,
  108. }]
  109. def _extract_videos(self, stories):
  110. for story in stories.values():
  111. if story.get('hasVideo'):
  112. yield self._parse_video(story)
  113. def _real_extract(self, url):
  114. series_id = self._match_id(url)
  115. stories = self._call_api(
  116. 'seriesStories', series_id, 'series stories')
  117. return self.playlist_result(self._extract_videos(stories), series_id)