2017-08-23 21:32:24 -05:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2021-02-14 12:48:26 -06:00
|
|
|
|
from ..compat import compat_HTTPError
|
2017-08-23 21:32:24 -05:00
|
|
|
|
from ..utils import (
|
2021-02-14 12:48:26 -06:00
|
|
|
|
ExtractorError,
|
2017-08-23 21:32:24 -05:00
|
|
|
|
int_or_none,
|
2021-02-14 12:48:26 -06:00
|
|
|
|
str_or_none,
|
2019-11-01 05:37:41 -05:00
|
|
|
|
strip_or_none,
|
2021-02-14 12:48:26 -06:00
|
|
|
|
try_get,
|
2017-08-23 21:32:24 -05:00
|
|
|
|
unified_timestamp,
|
2017-09-22 19:25:15 -05:00
|
|
|
|
update_url_query,
|
2017-08-23 21:32:24 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KakaoIE(InfoExtractor):
|
2019-11-01 05:37:41 -05:00
|
|
|
|
_VALID_URL = r'https?://(?:play-)?tv\.kakao\.com/(?:channel/\d+|embed/player)/cliplink/(?P<id>\d+|[^?#&]+@my)'
|
|
|
|
|
_API_BASE_TMPL = 'http://tv.kakao.com/api/v1/ft/cliplinks/%s/'
|
2017-08-23 21:32:24 -05:00
|
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'http://tv.kakao.com/channel/2671005/cliplink/301965083',
|
|
|
|
|
'md5': '702b2fbdeb51ad82f5c904e8c0766340',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '301965083',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': '乃木坂46 バナナマン 「3期生紹介コーナーが始動!顔高低差GPも!」 『乃木坂工事中』',
|
2021-02-14 12:48:26 -06:00
|
|
|
|
'uploader_id': '2671005',
|
2017-08-23 21:32:24 -05:00
|
|
|
|
'uploader': '그랑그랑이',
|
|
|
|
|
'timestamp': 1488160199,
|
|
|
|
|
'upload_date': '20170227',
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://tv.kakao.com/channel/2653210/cliplink/300103180',
|
|
|
|
|
'md5': 'a8917742069a4dd442516b86e7d66529',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '300103180',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'description': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)\r\n\r\n[쇼! 음악중심] 20160611, 507회',
|
|
|
|
|
'title': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)',
|
2021-02-14 12:48:26 -06:00
|
|
|
|
'uploader_id': '2653210',
|
2019-11-01 05:37:41 -05:00
|
|
|
|
'uploader': '쇼! 음악중심',
|
2017-08-23 21:32:24 -05:00
|
|
|
|
'timestamp': 1485684628,
|
|
|
|
|
'upload_date': '20170129',
|
|
|
|
|
}
|
2021-02-14 12:48:26 -06:00
|
|
|
|
}, {
|
|
|
|
|
# geo restricted
|
|
|
|
|
'url': 'https://tv.kakao.com/channel/3643855/cliplink/412069491',
|
|
|
|
|
'only_matching': True,
|
2017-08-23 21:32:24 -05:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
video_id = self._match_id(url)
|
2019-11-01 05:37:41 -05:00
|
|
|
|
display_id = video_id.rstrip('@my')
|
|
|
|
|
api_base = self._API_BASE_TMPL % video_id
|
2017-08-23 21:32:24 -05:00
|
|
|
|
|
2017-09-22 19:25:15 -05:00
|
|
|
|
player_header = {
|
|
|
|
|
'Referer': update_url_query(
|
|
|
|
|
'http://tv.kakao.com/embed/player/cliplink/%s' % video_id, {
|
|
|
|
|
'service': 'kakao_tv',
|
|
|
|
|
'autoplay': '1',
|
|
|
|
|
'profile': 'HIGH',
|
|
|
|
|
'wmode': 'transparent',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 05:37:41 -05:00
|
|
|
|
query = {
|
2017-09-22 19:25:15 -05:00
|
|
|
|
'player': 'monet_html5',
|
|
|
|
|
'referer': url,
|
|
|
|
|
'uuid': '',
|
|
|
|
|
'service': 'kakao_tv',
|
|
|
|
|
'section': '',
|
|
|
|
|
'dteType': 'PC',
|
2019-11-01 05:37:41 -05:00
|
|
|
|
'fields': ','.join([
|
|
|
|
|
'-*', 'tid', 'clipLink', 'displayTitle', 'clip', 'title',
|
|
|
|
|
'description', 'channelId', 'createTime', 'duration', 'playCount',
|
2021-02-14 12:48:26 -06:00
|
|
|
|
'likeCount', 'commentCount', 'tagList', 'channel', 'name', 'thumbnailUrl',
|
2019-11-01 06:40:41 -05:00
|
|
|
|
'videoOutputList', 'width', 'height', 'kbps', 'profile', 'label'])
|
2017-09-22 19:25:15 -05:00
|
|
|
|
}
|
2017-08-23 21:32:24 -05:00
|
|
|
|
|
|
|
|
|
impress = self._download_json(
|
2019-11-01 05:37:41 -05:00
|
|
|
|
api_base + 'impress', display_id, 'Downloading video info',
|
2017-09-22 19:25:15 -05:00
|
|
|
|
query=query, headers=player_header)
|
|
|
|
|
|
|
|
|
|
clip_link = impress['clipLink']
|
|
|
|
|
clip = clip_link['clip']
|
|
|
|
|
|
|
|
|
|
title = clip.get('title') or clip_link.get('displayTitle')
|
2017-08-23 21:32:24 -05:00
|
|
|
|
|
2021-02-14 12:48:26 -06:00
|
|
|
|
query.update({
|
|
|
|
|
'fields': '-*,code,message,url',
|
|
|
|
|
'tid': impress.get('tid') or '',
|
|
|
|
|
})
|
2017-08-23 21:32:24 -05:00
|
|
|
|
|
|
|
|
|
formats = []
|
2021-02-14 12:48:26 -06:00
|
|
|
|
for fmt in (clip.get('videoOutputList') or []):
|
2017-08-23 21:32:24 -05:00
|
|
|
|
try:
|
|
|
|
|
profile_name = fmt['profile']
|
2019-11-01 06:40:41 -05:00
|
|
|
|
if profile_name == 'AUDIO':
|
|
|
|
|
continue
|
2021-02-14 12:48:26 -06:00
|
|
|
|
query['profile'] = profile_name
|
|
|
|
|
try:
|
|
|
|
|
fmt_url_json = self._download_json(
|
|
|
|
|
api_base + 'raw/videolocation', display_id,
|
|
|
|
|
'Downloading video URL for profile %s' % profile_name,
|
|
|
|
|
query=query, headers=player_header)
|
|
|
|
|
except ExtractorError as e:
|
|
|
|
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
|
|
|
|
|
resp = self._parse_json(e.cause.read().decode(), video_id)
|
|
|
|
|
if resp.get('code') == 'GeoBlocked':
|
|
|
|
|
self.raise_geo_restricted()
|
2017-08-23 21:32:24 -05:00
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
fmt_url = fmt_url_json['url']
|
|
|
|
|
formats.append({
|
|
|
|
|
'url': fmt_url,
|
|
|
|
|
'format_id': profile_name,
|
|
|
|
|
'width': int_or_none(fmt.get('width')),
|
|
|
|
|
'height': int_or_none(fmt.get('height')),
|
|
|
|
|
'format_note': fmt.get('label'),
|
2019-11-01 06:40:41 -05:00
|
|
|
|
'filesize': int_or_none(fmt.get('filesize')),
|
|
|
|
|
'tbr': int_or_none(fmt.get('kbps')),
|
2017-08-23 21:32:24 -05:00
|
|
|
|
})
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
2017-09-22 19:25:15 -05:00
|
|
|
|
return {
|
2019-11-01 05:37:41 -05:00
|
|
|
|
'id': display_id,
|
2017-09-22 19:25:15 -05:00
|
|
|
|
'title': title,
|
2019-11-01 05:37:41 -05:00
|
|
|
|
'description': strip_or_none(clip.get('description')),
|
2021-02-14 12:48:26 -06:00
|
|
|
|
'uploader': try_get(clip_link, lambda x: x['channel']['name']),
|
|
|
|
|
'uploader_id': str_or_none(clip_link.get('channelId')),
|
|
|
|
|
'thumbnail': clip.get('thumbnailUrl'),
|
2017-09-22 19:25:15 -05:00
|
|
|
|
'timestamp': unified_timestamp(clip_link.get('createTime')),
|
|
|
|
|
'duration': int_or_none(clip.get('duration')),
|
|
|
|
|
'view_count': int_or_none(clip.get('playCount')),
|
|
|
|
|
'like_count': int_or_none(clip.get('likeCount')),
|
|
|
|
|
'comment_count': int_or_none(clip.get('commentCount')),
|
|
|
|
|
'formats': formats,
|
2019-11-01 05:37:41 -05:00
|
|
|
|
'tags': clip.get('tagList'),
|
2017-09-22 19:25:15 -05:00
|
|
|
|
}
|