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