logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

storyfire.py (5497B)


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