2 from __future__ import unicode_literals
3 from datetime import date, datetime
5 from .common import InfoExtractor
6 from ..compat import compat_str
7 from ..utils import int_or_none, UnsupportedError
9 MOMENT_URL_FORMAT = 'https://cdn.younow.com/php/api/moment/fetch/id=%s'
10 STREAM_URL_FORMAT = 'https://hls.younow.com/momentsplaylists/live/%s/%s.m3u8'
13 class YouNowIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?younow\.com/(?P<id>[^/]+)'
16 'url': 'https://www.younow.com/AmandaPadeezy',
18 'id': 'AmandaPadeezy',
21 'title': 'March 26, 2017',
22 'description': 'YouNow is the best way to broadcast live and get an audience to watch you.',
23 'thumbnail': 'https://ynassets.s3.amazonaws.com/broadcast/live/157869188/157869188.jpg',
25 'categories': ['girls'],
26 'uploader': 'AmandaPadeezy',
27 'uploader_id': '6716501',
28 'uploader_url': 'https://www.younow.com/AmandaPadeezy',
29 'creator': 'AmandaPadeezy',
31 'url': 'https://cdn.younow.com/php/api/broadcast/videoPath/hls=1/broadcastId=157869188/channelId=6716501',
38 def _real_extract(self, url):
39 username = self._match_id(url)
40 data = self._download_json('https://api.younow.com/php/api/broadcast/info/curId=0/user=%s' % (username), username)
43 stream_url = 'https://cdn.younow.com/php/api/broadcast/videoPath/hls=1/broadcastId=%s/channelId=%s' % (
44 data.get('broadcastId'),
48 raise UnsupportedError('Unsupported stream or user is not streaming at this time')
50 webpage = self._download_webpage(url, username)
52 uploader = data['user']['profileUrlString']
58 title = date.today().strftime('%B %d, %Y')
64 'description': self._og_search_description(webpage),
65 'thumbnail': data.get('awsUrl'),
66 'tags': data.get('tags'),
67 'categories': data.get('tags'),
69 'uploader_id': data.get('userId'),
70 'uploader_url': 'https://www.younow.com/%s' % (data['user']['profileUrlString'],),
72 'view_count': int_or_none(data.get('viewers')),
73 'like_count': int_or_none(data.get('likes')),
82 def _moment_to_entry(item):
83 title = item.get('text')
84 title_type = item.get('titleType')
87 title = 'YouNow %s' % item.get('titleType')
89 title = 'YouNow moment'
92 'id': compat_str(item['momentId']),
94 'view_count': int_or_none(item.get('views')),
95 'like_count': int_or_none(item.get('likes')),
96 'timestamp': int_or_none(item.get('created')),
98 'url': STREAM_URL_FORMAT % (item['momentId'], item['momentId']),
105 entry['uploader'] = entry['creator'] = item['owner']['name']
106 entry['uploader_url'] = 'https://www.younow.com/%s' % (item['owner']['name'],)
107 entry['uploader_id'] = item['owner']['userId']
114 class YouNowChannelIE(InfoExtractor):
115 _VALID_URL = r'https?://(?:www\.)?younow\.com/(?P<id>[^/]+)/channel'
117 'url': 'https://www.younow.com/Kate_Swiz/channel',
119 'title': 'Kate_Swiz moments'
124 MOMENTS_URL_FORMAT = 'https://cdn.younow.com/php/api/moment/profile/channelId=%s/createdBefore=%d/records=20'
126 def _real_extract(self, url):
128 username = self._match_id(url)
129 user_info = self._download_json('https://api.younow.com/php/api/broadcast/info/curId=0/user=%s' % (username), username, note='Downloading user information')
130 channel_id = user_info['userId']
133 moment_ids_processed = []
138 cb = datetime.fromtimestamp(created_before)
141 info = self._download_json(self.MOMENTS_URL_FORMAT % (channel_id, created_before), username, note='Downloading moments data (created before %s)' % (cb))
143 for item in info['items']:
144 if item['type'] == 'moment':
145 entry = _moment_to_entry(item)
146 moment_ids_processed.append(entry['id'])
147 entries.append(entry)
148 elif item['type'] == 'collection':
149 moment_ids += [compat_str(x) for x in item['momentsIds']]
152 created_before = int_or_none(item['created'])
158 not info['hasMore'] or
159 'items' not in info or
163 for mid in set(moment_ids):
164 if mid in moment_ids_processed:
166 item = self._download_json(MOMENT_URL_FORMAT % (mid), mid)
167 entries.append(_moment_to_entry(item['item']))
169 return self.playlist_result(entries, playlist_title='%s moments' % (username))
172 class YouNowMomentIE(InfoExtractor):
173 _VALID_URL = r'https?://(?:www\.)?younow\.com/[^/]+/(?P<id>[^/]+)/[^/]+'
175 'url': 'https://www.younow.com/GABO.../20712117/36319236/3b316doc/m',
179 'title': 'YouNow capture',
182 'timestamp': 1490432040,
184 'url': 'https://hls.younow.com/momentsplaylists/live/20712117/20712117.m3u8',
188 'upload_date': '20170325',
189 'uploader': 'GABO...',
190 'uploader_id': 35917228,
194 def _real_extract(self, url):
195 mid = self._match_id(url)
196 item = self._download_json(MOMENT_URL_FORMAT % (mid), mid)
197 return _moment_to_entry(item['item'])