3 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
15 class KakaoIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:play-)?tv\.kakao\.com/(?:channel/\d+|embed/player)/cliplink/(?P<id>\d+|[^?#&]+@my)'
17 _API_BASE_TMPL = 'http://tv.kakao.com/api/v1/ft/cliplinks/%s/'
20 'url': 'http://tv.kakao.com/channel/2671005/cliplink/301965083',
21 'md5': '702b2fbdeb51ad82f5c904e8c0766340',
25 'title': '乃木坂46 バナナマン 「3期生紹介コーナーが始動!顔高低差GPも!」 『乃木坂工事中』',
26 'uploader_id': 2671005,
28 'timestamp': 1488160199,
29 'upload_date': '20170227',
32 'url': 'http://tv.kakao.com/channel/2653210/cliplink/300103180',
33 'md5': 'a8917742069a4dd442516b86e7d66529',
37 'description': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)\r\n\r\n[쇼! 음악중심] 20160611, 507회',
38 'title': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)',
39 'uploader_id': 2653210,
40 'uploader': '쇼! 음악중심',
41 'timestamp': 1485684628,
42 'upload_date': '20170129',
46 def _real_extract(self, url):
47 video_id = self._match_id(url)
48 display_id = video_id.rstrip('@my')
49 api_base = self._API_BASE_TMPL % video_id
52 'Referer': update_url_query(
53 'http://tv.kakao.com/embed/player/cliplink/%s' % video_id, {
54 'service': 'kakao_tv',
57 'wmode': 'transparent',
62 'player': 'monet_html5',
65 'service': 'kakao_tv',
69 '-*', 'tid', 'clipLink', 'displayTitle', 'clip', 'title',
70 'description', 'channelId', 'createTime', 'duration', 'playCount',
71 'likeCount', 'commentCount', 'tagList', 'channel', 'name',
72 'clipChapterThumbnailList', 'thumbnailUrl', 'timeInSec', 'isDefault'])
75 impress = self._download_json(
76 api_base + 'impress', display_id, 'Downloading video info',
77 query=query, headers=player_header)
79 clip_link = impress['clipLink']
80 clip = clip_link['clip']
82 title = clip.get('title') or clip_link.get('displayTitle')
84 tid = impress.get('tid', '')
87 'fields': '-*,outputList,profile,width,height,label,filesize',
91 raw = self._download_json(
92 api_base + 'raw', display_id, 'Downloading video formats info',
93 query=query, headers=player_header)
96 for fmt in raw.get('outputList', []):
98 profile_name = fmt['profile']
100 'profile': profile_name,
103 fmt_url_json = self._download_json(
104 api_base + 'raw/videolocation', display_id,
105 'Downloading video URL for profile %s' % profile_name,
106 query=query, headers=player_header, fatal=False)
108 if fmt_url_json is None:
111 fmt_url = fmt_url_json['url']
114 'format_id': profile_name,
115 'width': int_or_none(fmt.get('width')),
116 'height': int_or_none(fmt.get('height')),
117 'format_note': fmt.get('label'),
118 'filesize': int_or_none(fmt.get('filesize'))
122 self._sort_formats(formats)
125 for thumb in clip.get('clipChapterThumbnailList', []):
127 'url': thumb.get('thumbnailUrl'),
128 'id': compat_str(thumb.get('timeInSec')),
129 'preference': -1 if thumb.get('isDefault') else 0
131 top_thumbnail = clip.get('thumbnailUrl')
134 'url': top_thumbnail,
141 'description': strip_or_none(clip.get('description')),
142 'uploader': clip_link.get('channel', {}).get('name'),
143 'uploader_id': clip_link.get('channelId'),
144 'thumbnails': thumbs,
145 'timestamp': unified_timestamp(clip_link.get('createTime')),
146 'duration': int_or_none(clip.get('duration')),
147 'view_count': int_or_none(clip.get('playCount')),
148 'like_count': int_or_none(clip.get('likeCount')),
149 'comment_count': int_or_none(clip.get('commentCount')),
151 'tags': clip.get('tagList'),