]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/younow.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
15 CDN_API_BASE
= 'https://cdn.younow.com/php/api'
16 MOMENT_URL_FORMAT
= '%s/moment/fetch/id=%%s' % CDN_API_BASE
19 class YouNowLiveIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:www\.)?younow\.com/(?P<id>[^/?#&]+)'
22 'url': 'https://www.younow.com/AmandaPadeezy',
24 'id': 'AmandaPadeezy',
27 'title': 'March 26, 2017',
28 'thumbnail': r
're:^https?://.*\.jpg$',
30 'categories': ['girls'],
31 'uploader': 'AmandaPadeezy',
32 'uploader_id': '6716501',
33 'uploader_url': 'https://www.younow.com/AmandaPadeezy',
34 'creator': 'AmandaPadeezy',
40 def suitable(cls
, url
):
42 if YouNowChannelIE
.suitable(url
) or YouNowMomentIE
.suitable(url
)
43 else super(YouNowLiveIE
, cls
).suitable(url
))
45 def _real_extract(self
, url
):
46 username
= self
._match
_id
(url
)
48 data
= self
._download
_json
(
49 'https://api.younow.com/php/api/broadcast/info/curId=0/user=%s'
52 if data
.get('errorCode') != 0:
53 raise ExtractorError(data
['errorMsg'], expected
=True)
56 data
, lambda x
: x
['user']['profileUrlString'],
57 compat_str
) or username
63 'thumbnail': data
.get('awsUrl'),
64 'tags': data
.get('tags'),
65 'categories': data
.get('tags'),
67 'uploader_id': data
.get('userId'),
68 'uploader_url': 'https://www.younow.com/%s' % username
,
70 'view_count': int_or_none(data
.get('viewers')),
71 'like_count': int_or_none(data
.get('likes')),
73 'url': '%s/broadcast/videoPath/hls=1/broadcastId=%s/channelId=%s'
74 % (CDN_API_BASE
, data
['broadcastId'], data
['userId']),
81 def _extract_moment(item
, fatal
=True):
82 moment_id
= item
.get('momentId')
86 raise ExtractorError('Unable to extract moment id')
88 moment_id
= compat_str(moment_id
)
90 title
= item
.get('text')
92 title
= 'YouNow %s' % (
93 item
.get('momentType') or item
.get('titleType') or 'moment')
95 uploader
= try_get(item
, lambda x
: x
['owner']['name'], compat_str
)
96 uploader_id
= try_get(item
, lambda x
: x
['owner']['userId'])
97 uploader_url
= format_field(uploader
, template
='https://www.younow.com/%s')
100 'extractor_key': 'YouNowMoment',
103 'view_count': int_or_none(item
.get('views')),
104 'like_count': int_or_none(item
.get('likes')),
105 'timestamp': int_or_none(item
.get('created')),
107 'uploader': uploader
,
108 'uploader_id': uploader_id
,
109 'uploader_url': uploader_url
,
111 'url': 'https://hls.younow.com/momentsplaylists/live/%s/%s.m3u8'
112 % (moment_id
, moment_id
),
114 'protocol': 'm3u8_native',
121 class YouNowChannelIE(InfoExtractor
):
122 _VALID_URL
= r
'https?://(?:www\.)?younow\.com/(?P<id>[^/]+)/channel'
124 'url': 'https://www.younow.com/its_Kateee_/channel',
127 'title': 'its_Kateee_ moments'
129 'playlist_mincount': 8,
132 def _entries(self
, username
, channel_id
):
134 for page_num
in itertools
.count(1):
135 if created_before
is None:
137 info
= self
._download
_json
(
138 '%s/moment/profile/channelId=%s/createdBefore=%d/records=20'
139 % (CDN_API_BASE
, channel_id
, created_before
), username
,
140 note
='Downloading moments page %d' % page_num
)
141 items
= info
.get('items')
142 if not items
or not isinstance(items
, list):
145 if not isinstance(item
, dict):
147 item_type
= item
.get('type')
148 if item_type
== 'moment':
149 entry
= _extract_moment(item
, fatal
=False)
152 elif item_type
== 'collection':
153 moments
= item
.get('momentsIds')
154 if isinstance(moments
, list):
155 for moment_id
in moments
:
156 m
= self
._download
_json
(
157 MOMENT_URL_FORMAT
% moment_id
, username
,
158 note
='Downloading %s moment JSON' % moment_id
,
160 if m
and isinstance(m
, dict) and m
.get('item'):
161 entry
= _extract_moment(m
['item'])
164 created_before
= int_or_none(item
.get('created'))
166 def _real_extract(self
, url
):
167 username
= self
._match
_id
(url
)
168 channel_id
= compat_str(self
._download
_json
(
169 'https://api.younow.com/php/api/broadcast/info/curId=0/user=%s'
170 % username
, username
, note
='Downloading user information')['userId'])
171 return self
.playlist_result(
172 self
._entries
(username
, channel_id
), channel_id
,
173 '%s moments' % username
)
176 class YouNowMomentIE(InfoExtractor
):
177 _VALID_URL
= r
'https?://(?:www\.)?younow\.com/[^/]+/(?P<id>[^/?#&]+)'
179 'url': 'https://www.younow.com/GABO.../20712117/36319236/3b316doc/m',
180 'md5': 'a30c70eadb9fb39a1aa3c8c0d22a0807',
184 'title': 'YouNow capture',
187 'timestamp': 1490432040,
188 'upload_date': '20170325',
189 'uploader': 'GABO...',
190 'uploader_id': 35917228,
195 def suitable(cls
, url
):
197 if YouNowChannelIE
.suitable(url
)
198 else super(YouNowMomentIE
, cls
).suitable(url
))
200 def _real_extract(self
, url
):
201 video_id
= self
._match
_id
(url
)
202 item
= self
._download
_json
(MOMENT_URL_FORMAT
% video_id
, video_id
)
203 return _extract_moment(item
['item'])