import itertools
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
ExtractorError,
format_field,
int_or_none,
+ str_or_none,
try_get,
)
CDN_API_BASE = 'https://cdn.younow.com/php/api'
-MOMENT_URL_FORMAT = '%s/moment/fetch/id=%%s' % CDN_API_BASE
+MOMENT_URL_FORMAT = f'{CDN_API_BASE}/moment/fetch/id=%s'
class YouNowLiveIE(InfoExtractor):
def suitable(cls, url):
return (False
if YouNowChannelIE.suitable(url) or YouNowMomentIE.suitable(url)
- else super(YouNowLiveIE, cls).suitable(url))
+ else super().suitable(url))
def _real_extract(self, url):
username = self._match_id(url)
data = self._download_json(
- 'https://api.younow.com/php/api/broadcast/info/curId=0/user=%s'
- % username, username)
+ f'https://api.younow.com/php/api/broadcast/info/curId=0/user={username}', username)
if data.get('errorCode') != 0:
raise ExtractorError(data['errorMsg'], expected=True)
uploader = try_get(
data, lambda x: x['user']['profileUrlString'],
- compat_str) or username
+ str) or username
return {
'id': uploader,
'categories': data.get('tags'),
'uploader': uploader,
'uploader_id': data.get('userId'),
- 'uploader_url': 'https://www.younow.com/%s' % username,
+ 'uploader_url': f'https://www.younow.com/{username}',
'creator': uploader,
'view_count': int_or_none(data.get('viewers')),
'like_count': int_or_none(data.get('likes')),
'formats': [{
- 'url': '%s/broadcast/videoPath/hls=1/broadcastId=%s/channelId=%s'
- % (CDN_API_BASE, data['broadcastId'], data['userId']),
+ 'url': '{}/broadcast/videoPath/hls=1/broadcastId={}/channelId={}'.format(CDN_API_BASE, data['broadcastId'], data['userId']),
'ext': 'mp4',
'protocol': 'm3u8',
}],
return
raise ExtractorError('Unable to extract moment id')
- moment_id = compat_str(moment_id)
+ moment_id = str(moment_id)
title = item.get('text')
if not title:
title = 'YouNow %s' % (
item.get('momentType') or item.get('titleType') or 'moment')
- uploader = try_get(item, lambda x: x['owner']['name'], compat_str)
+ uploader = try_get(item, lambda x: x['owner']['name'], str)
uploader_id = try_get(item, lambda x: x['owner']['userId'])
- uploader_url = format_field(uploader, template='https://www.younow.com/%s')
+ uploader_url = format_field(uploader, None, 'https://www.younow.com/%s')
- entry = {
+ return {
'extractor_key': 'YouNowMoment',
'id': moment_id,
'title': title,
'timestamp': int_or_none(item.get('created')),
'creator': uploader,
'uploader': uploader,
- 'uploader_id': uploader_id,
+ 'uploader_id': str_or_none(uploader_id),
'uploader_url': uploader_url,
'formats': [{
- 'url': 'https://hls.younow.com/momentsplaylists/live/%s/%s.m3u8'
- % (moment_id, moment_id),
+ 'url': f'https://hls.younow.com/momentsplaylists/live/{moment_id}/{moment_id}.m3u8',
'ext': 'mp4',
'protocol': 'm3u8_native',
}],
}
- return entry
-
class YouNowChannelIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?younow\.com/(?P<id>[^/]+)/channel'
'url': 'https://www.younow.com/its_Kateee_/channel',
'info_dict': {
'id': '14629760',
- 'title': 'its_Kateee_ moments'
+ 'title': 'its_Kateee_ moments',
},
'playlist_mincount': 8,
}
if created_before is None:
break
info = self._download_json(
- '%s/moment/profile/channelId=%s/createdBefore=%d/records=20'
- % (CDN_API_BASE, channel_id, created_before), username,
- note='Downloading moments page %d' % page_num)
+ f'{CDN_API_BASE}/moment/profile/channelId={channel_id}/createdBefore={created_before}/records=20',
+ username, note=f'Downloading moments page {page_num}')
items = info.get('items')
if not items or not isinstance(items, list):
break
for moment_id in moments:
m = self._download_json(
MOMENT_URL_FORMAT % moment_id, username,
- note='Downloading %s moment JSON' % moment_id,
+ note=f'Downloading {moment_id} moment JSON',
fatal=False)
if m and isinstance(m, dict) and m.get('item'):
entry = _extract_moment(m['item'])
def _real_extract(self, url):
username = self._match_id(url)
- channel_id = compat_str(self._download_json(
- 'https://api.younow.com/php/api/broadcast/info/curId=0/user=%s'
- % username, username, note='Downloading user information')['userId'])
+ channel_id = str(self._download_json(
+ f'https://api.younow.com/php/api/broadcast/info/curId=0/user={username}',
+ username, note='Downloading user information')['userId'])
return self.playlist_result(
self._entries(username, channel_id), channel_id,
- '%s moments' % username)
+ f'{username} moments')
class YouNowMomentIE(InfoExtractor):
'timestamp': 1490432040,
'upload_date': '20170325',
'uploader': 'GABO...',
- 'uploader_id': 35917228,
+ 'uploader_id': '35917228',
},
}
def suitable(cls, url):
return (False
if YouNowChannelIE.suitable(url)
- else super(YouNowMomentIE, cls).suitable(url))
+ else super().suitable(url))
def _real_extract(self, url):
video_id = self._match_id(url)