2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
14 CDN_API_BASE = 'https://cdn.younow.com/php/api'
15 MOMENT_URL_FORMAT = '%s/moment/fetch/id=%%s' % CDN_API_BASE
18 class YouNowLiveIE(InfoExtractor):
19 _VALID_URL = r'https?://(?:www\.)?younow\.com/(?P<id>[^/?#&]+)'
21 'url': 'https://www.younow.com/AmandaPadeezy',
23 'id': 'AmandaPadeezy',
26 'title': 'March 26, 2017',
27 'thumbnail': r're:^https?://.*\.jpg$',
29 'categories': ['girls'],
30 'uploader': 'AmandaPadeezy',
31 'uploader_id': '6716501',
32 'uploader_url': 'https://www.younow.com/AmandaPadeezy',
33 'creator': 'AmandaPadeezy',
39 def suitable(cls, url):
41 if YouNowChannelIE.suitable(url) or YouNowMomentIE.suitable(url)
42 else super(YouNowLiveIE, cls).suitable(url))
44 def _real_extract(self, url):
45 username = self._match_id(url)
47 data = self._download_json(
48 'https://api.younow.com/php/api/broadcast/info/curId=0/user=%s'
51 if data.get('errorCode') != 0:
52 raise ExtractorError(data['errorMsg'], expected=True)
55 data, lambda x: x['user']['profileUrlString'],
56 compat_str) or username
61 'title': self._live_title(uploader),
62 'thumbnail': data.get('awsUrl'),
63 'tags': data.get('tags'),
64 'categories': data.get('tags'),
66 'uploader_id': data.get('userId'),
67 'uploader_url': 'https://www.younow.com/%s' % username,
69 'view_count': int_or_none(data.get('viewers')),
70 'like_count': int_or_none(data.get('likes')),
72 'url': '%s/broadcast/videoPath/hls=1/broadcastId=%s/channelId=%s'
73 % (CDN_API_BASE, data['broadcastId'], data['userId']),
80 def _extract_moment(item, fatal=True):
81 moment_id = item.get('momentId')
85 raise ExtractorError('Unable to extract moment id')
87 moment_id = compat_str(moment_id)
89 title = item.get('text')
91 title = 'YouNow %s' % (
92 item.get('momentType') or item.get('titleType') or 'moment')
94 uploader = try_get(item, lambda x: x['owner']['name'], compat_str)
95 uploader_id = try_get(item, lambda x: x['owner']['userId'])
96 uploader_url = 'https://www.younow.com/%s' % uploader if uploader else None
99 'extractor_key': 'YouNowMoment',
102 'view_count': int_or_none(item.get('views')),
103 'like_count': int_or_none(item.get('likes')),
104 'timestamp': int_or_none(item.get('created')),
106 'uploader': uploader,
107 'uploader_id': uploader_id,
108 'uploader_url': uploader_url,
110 'url': 'https://hls.younow.com/momentsplaylists/live/%s/%s.m3u8'
111 % (moment_id, moment_id),
113 'protocol': 'm3u8_native',
120 class YouNowChannelIE(InfoExtractor):
121 _VALID_URL = r'https?://(?:www\.)?younow\.com/(?P<id>[^/]+)/channel'
123 'url': 'https://www.younow.com/its_Kateee_/channel',
126 'title': 'its_Kateee_ moments'
128 'playlist_mincount': 8,
131 def _entries(self, username, channel_id):
133 for page_num in itertools.count(1):
134 if created_before is None:
136 info = self._download_json(
137 '%s/moment/profile/channelId=%s/createdBefore=%d/records=20'
138 % (CDN_API_BASE, channel_id, created_before), username,
139 note='Downloading moments page %d' % page_num)
140 items = info.get('items')
141 if not items or not isinstance(items, list):
144 if not isinstance(item, dict):
146 item_type = item.get('type')
147 if item_type == 'moment':
148 entry = _extract_moment(item, fatal=False)
151 elif item_type == 'collection':
152 moments = item.get('momentsIds')
153 if isinstance(moments, list):
154 for moment_id in moments:
155 m = self._download_json(
156 MOMENT_URL_FORMAT % moment_id, username,
157 note='Downloading %s moment JSON' % moment_id,
159 if m and isinstance(m, dict) and m.get('item'):
160 entry = _extract_moment(m['item'])
163 created_before = int_or_none(item.get('created'))
165 def _real_extract(self, url):
166 username = self._match_id(url)
167 channel_id = compat_str(self._download_json(
168 'https://api.younow.com/php/api/broadcast/info/curId=0/user=%s'
169 % username, username, note='Downloading user information')['userId'])
170 return self.playlist_result(
171 self._entries(username, channel_id), channel_id,
172 '%s moments' % username)
175 class YouNowMomentIE(InfoExtractor):
176 _VALID_URL = r'https?://(?:www\.)?younow\.com/[^/]+/(?P<id>[^/?#&]+)'
178 'url': 'https://www.younow.com/GABO.../20712117/36319236/3b316doc/m',
179 'md5': 'a30c70eadb9fb39a1aa3c8c0d22a0807',
183 'title': 'YouNow capture',
186 'timestamp': 1490432040,
187 'upload_date': '20170325',
188 'uploader': 'GABO...',
189 'uploader_id': 35917228,
194 def suitable(cls, url):
196 if YouNowChannelIE.suitable(url)
197 else super(YouNowMomentIE, cls).suitable(url))
199 def _real_extract(self, url):
200 video_id = self._match_id(url)
201 item = self._download_json(MOMENT_URL_FORMAT % video_id, video_id)
202 return _extract_moment(item['item'])