3 from .common
import InfoExtractor
12 CDN_API_BASE
= 'https://cdn.younow.com/php/api'
13 MOMENT_URL_FORMAT
= f
'{CDN_API_BASE}/moment/fetch/id=%s'
16 class YouNowLiveIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?younow\.com/(?P<id>[^/?#&]+)'
19 'url': 'https://www.younow.com/AmandaPadeezy',
21 'id': 'AmandaPadeezy',
24 'title': 'March 26, 2017',
25 'thumbnail': r
're:^https?://.*\.jpg$',
27 'categories': ['girls'],
28 'uploader': 'AmandaPadeezy',
29 'uploader_id': '6716501',
30 'uploader_url': 'https://www.younow.com/AmandaPadeezy',
31 'creator': 'AmandaPadeezy',
37 def suitable(cls
, url
):
39 if YouNowChannelIE
.suitable(url
) or YouNowMomentIE
.suitable(url
)
40 else super().suitable(url
))
42 def _real_extract(self
, url
):
43 username
= self
._match
_id
(url
)
45 data
= self
._download
_json
(
46 f
'https://api.younow.com/php/api/broadcast/info/curId=0/user={username}', username
)
48 if data
.get('errorCode') != 0:
49 raise ExtractorError(data
['errorMsg'], expected
=True)
52 data
, lambda x
: x
['user']['profileUrlString'],
59 'thumbnail': data
.get('awsUrl'),
60 'tags': data
.get('tags'),
61 'categories': data
.get('tags'),
63 'uploader_id': data
.get('userId'),
64 'uploader_url': f
'https://www.younow.com/{username}',
66 'view_count': int_or_none(data
.get('viewers')),
67 'like_count': int_or_none(data
.get('likes')),
69 'url': '{}/broadcast/videoPath/hls=1/broadcastId={}/channelId={}'.format(CDN_API_BASE
, data
['broadcastId'], data
['userId']),
76 def _extract_moment(item
, fatal
=True):
77 moment_id
= item
.get('momentId')
81 raise ExtractorError('Unable to extract moment id')
83 moment_id
= str(moment_id
)
85 title
= item
.get('text')
87 title
= 'YouNow %s' % (
88 item
.get('momentType') or item
.get('titleType') or 'moment')
90 uploader
= try_get(item
, lambda x
: x
['owner']['name'], str)
91 uploader_id
= try_get(item
, lambda x
: x
['owner']['userId'])
92 uploader_url
= format_field(uploader
, None, 'https://www.younow.com/%s')
95 'extractor_key': 'YouNowMoment',
98 'view_count': int_or_none(item
.get('views')),
99 'like_count': int_or_none(item
.get('likes')),
100 'timestamp': int_or_none(item
.get('created')),
102 'uploader': uploader
,
103 'uploader_id': str_or_none(uploader_id
),
104 'uploader_url': uploader_url
,
106 'url': f
'https://hls.younow.com/momentsplaylists/live/{moment_id}/{moment_id}.m3u8',
108 'protocol': 'm3u8_native',
113 class YouNowChannelIE(InfoExtractor
):
114 _VALID_URL
= r
'https?://(?:www\.)?younow\.com/(?P<id>[^/]+)/channel'
116 'url': 'https://www.younow.com/its_Kateee_/channel',
119 'title': 'its_Kateee_ moments',
121 'playlist_mincount': 8,
124 def _entries(self
, username
, channel_id
):
126 for page_num
in itertools
.count(1):
127 if created_before
is None:
129 info
= self
._download
_json
(
130 f
'{CDN_API_BASE}/moment/profile/channelId={channel_id}/createdBefore={created_before}/records=20',
131 username
, note
=f
'Downloading moments page {page_num}')
132 items
= info
.get('items')
133 if not items
or not isinstance(items
, list):
136 if not isinstance(item
, dict):
138 item_type
= item
.get('type')
139 if item_type
== 'moment':
140 entry
= _extract_moment(item
, fatal
=False)
143 elif item_type
== 'collection':
144 moments
= item
.get('momentsIds')
145 if isinstance(moments
, list):
146 for moment_id
in moments
:
147 m
= self
._download
_json
(
148 MOMENT_URL_FORMAT
% moment_id
, username
,
149 note
=f
'Downloading {moment_id} moment JSON',
151 if m
and isinstance(m
, dict) and m
.get('item'):
152 entry
= _extract_moment(m
['item'])
155 created_before
= int_or_none(item
.get('created'))
157 def _real_extract(self
, url
):
158 username
= self
._match
_id
(url
)
159 channel_id
= str(self
._download
_json
(
160 f
'https://api.younow.com/php/api/broadcast/info/curId=0/user={username}',
161 username
, note
='Downloading user information')['userId'])
162 return self
.playlist_result(
163 self
._entries
(username
, channel_id
), channel_id
,
164 f
'{username} moments')
167 class YouNowMomentIE(InfoExtractor
):
168 _VALID_URL
= r
'https?://(?:www\.)?younow\.com/[^/]+/(?P<id>[^/?#&]+)'
170 'url': 'https://www.younow.com/GABO.../20712117/36319236/3b316doc/m',
171 'md5': 'a30c70eadb9fb39a1aa3c8c0d22a0807',
175 'title': 'YouNow capture',
178 'timestamp': 1490432040,
179 'upload_date': '20170325',
180 'uploader': 'GABO...',
181 'uploader_id': '35917228',
186 def suitable(cls
, url
):
188 if YouNowChannelIE
.suitable(url
)
189 else super().suitable(url
))
191 def _real_extract(self
, url
):
192 video_id
= self
._match
_id
(url
)
193 item
= self
._download
_json
(MOMENT_URL_FORMAT
% video_id
, video_id
)
194 return _extract_moment(item
['item'])