]>
Commit | Line | Data |
---|---|---|
1c22d7a7 N |
1 | # coding: utf-8 |
2 | ||
3 | from __future__ import unicode_literals | |
4 | ||
5 | from .common import InfoExtractor | |
f70ddd4a | 6 | from ..compat import compat_str |
1c22d7a7 N |
7 | from ..utils import ( |
8 | int_or_none, | |
274bf5e4 | 9 | strip_or_none, |
f8fabc99 | 10 | traverse_obj, |
1c22d7a7 N |
11 | unified_timestamp, |
12 | ) | |
13 | ||
14 | ||
15 | class KakaoIE(InfoExtractor): | |
274bf5e4 | 16 | _VALID_URL = r'https?://(?:play-)?tv\.kakao\.com/(?:channel/\d+|embed/player)/cliplink/(?P<id>\d+|[^?#&]+@my)' |
4cd3053c U |
17 | _API_BASE_TMPL = 'http://tv.kakao.com/api/v1/ft/playmeta/cliplink/%s/' |
18 | _CDN_API = 'https://tv.kakao.com/katz/v1/ft/cliplink/%s/readyNplay?' | |
1c22d7a7 N |
19 | |
20 | _TESTS = [{ | |
21 | 'url': 'http://tv.kakao.com/channel/2671005/cliplink/301965083', | |
22 | 'md5': '702b2fbdeb51ad82f5c904e8c0766340', | |
23 | 'info_dict': { | |
24 | 'id': '301965083', | |
25 | 'ext': 'mp4', | |
26 | 'title': '乃木坂46 バナナマン 「3期生紹介コーナーが始動!顔高低差GPも!」 『乃木坂工事中』', | |
27 | 'uploader_id': 2671005, | |
28 | 'uploader': '그랑그랑이', | |
29 | 'timestamp': 1488160199, | |
30 | 'upload_date': '20170227', | |
31 | } | |
32 | }, { | |
33 | 'url': 'http://tv.kakao.com/channel/2653210/cliplink/300103180', | |
34 | 'md5': 'a8917742069a4dd442516b86e7d66529', | |
35 | 'info_dict': { | |
36 | 'id': '300103180', | |
37 | 'ext': 'mp4', | |
38 | 'description': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)\r\n\r\n[쇼! 음악중심] 20160611, 507회', | |
39 | 'title': '러블리즈 - Destiny (나의 지구) (Lovelyz - Destiny)', | |
40 | 'uploader_id': 2653210, | |
274bf5e4 | 41 | 'uploader': '쇼! 음악중심', |
1c22d7a7 N |
42 | 'timestamp': 1485684628, |
43 | 'upload_date': '20170129', | |
44 | } | |
45 | }] | |
46 | ||
47 | def _real_extract(self, url): | |
48 | video_id = self._match_id(url) | |
274bf5e4 | 49 | api_base = self._API_BASE_TMPL % video_id |
4cd3053c | 50 | cdn_api_base = self._CDN_API % video_id |
f70ddd4a | 51 | |
274bf5e4 | 52 | query = { |
f70ddd4a S |
53 | 'player': 'monet_html5', |
54 | 'referer': url, | |
55 | 'uuid': '', | |
56 | 'service': 'kakao_tv', | |
57 | 'section': '', | |
58 | 'dteType': 'PC', | |
274bf5e4 RA |
59 | 'fields': ','.join([ |
60 | '-*', 'tid', 'clipLink', 'displayTitle', 'clip', 'title', | |
61 | 'description', 'channelId', 'createTime', 'duration', 'playCount', | |
62 | 'likeCount', 'commentCount', 'tagList', 'channel', 'name', | |
e987ce4b RA |
63 | 'clipChapterThumbnailList', 'thumbnailUrl', 'timeInSec', 'isDefault', |
64 | 'videoOutputList', 'width', 'height', 'kbps', 'profile', 'label']) | |
f70ddd4a | 65 | } |
1c22d7a7 | 66 | |
4cd3053c U |
67 | api_json = self._download_json( |
68 | api_base, video_id, 'Downloading video info') | |
f70ddd4a | 69 | |
4cd3053c | 70 | clip_link = api_json['clipLink'] |
f70ddd4a S |
71 | clip = clip_link['clip'] |
72 | ||
73 | title = clip.get('title') or clip_link.get('displayTitle') | |
1c22d7a7 | 74 | |
1c22d7a7 | 75 | formats = [] |
e987ce4b | 76 | for fmt in clip.get('videoOutputList', []): |
f8fabc99 | 77 | profile_name = fmt.get('profile') |
78 | if not profile_name or profile_name == 'AUDIO': | |
79 | continue | |
80 | query.update({ | |
81 | 'profile': profile_name, | |
82 | 'fields': '-*,url', | |
83 | }) | |
1c22d7a7 | 84 | |
f8fabc99 | 85 | fmt_url_json = self._download_json( |
86 | cdn_api_base, video_id, | |
87 | 'Downloading video URL for profile %s' % profile_name, | |
88 | query=query, fatal=False) | |
89 | fmt_url = traverse_obj(fmt_url_json, ('videoLocation', 'url')) | |
90 | if not fmt_url: | |
91 | continue | |
92 | ||
93 | formats.append({ | |
94 | 'url': fmt_url, | |
95 | 'format_id': profile_name, | |
96 | 'width': int_or_none(fmt.get('width')), | |
97 | 'height': int_or_none(fmt.get('height')), | |
98 | 'format_note': fmt.get('label'), | |
99 | 'filesize': int_or_none(fmt.get('filesize')), | |
100 | 'tbr': int_or_none(fmt.get('kbps')), | |
101 | }) | |
1c22d7a7 | 102 | self._sort_formats(formats) |
1c22d7a7 | 103 | |
1c22d7a7 | 104 | thumbs = [] |
f8fabc99 | 105 | for thumb in clip.get('clipChapterThumbnailList') or []: |
1c22d7a7 N |
106 | thumbs.append({ |
107 | 'url': thumb.get('thumbnailUrl'), | |
108 | 'id': compat_str(thumb.get('timeInSec')), | |
109 | 'preference': -1 if thumb.get('isDefault') else 0 | |
110 | }) | |
f70ddd4a S |
111 | top_thumbnail = clip.get('thumbnailUrl') |
112 | if top_thumbnail: | |
113 | thumbs.append({ | |
114 | 'url': top_thumbnail, | |
115 | 'preference': 10, | |
116 | }) | |
1c22d7a7 | 117 | |
f70ddd4a | 118 | return { |
4cd3053c | 119 | 'id': video_id, |
f70ddd4a | 120 | 'title': title, |
274bf5e4 | 121 | 'description': strip_or_none(clip.get('description')), |
f8fabc99 | 122 | 'uploader': traverse_obj(clip_link, ('channel', 'name')), |
f70ddd4a S |
123 | 'uploader_id': clip_link.get('channelId'), |
124 | 'thumbnails': thumbs, | |
125 | 'timestamp': unified_timestamp(clip_link.get('createTime')), | |
126 | 'duration': int_or_none(clip.get('duration')), | |
127 | 'view_count': int_or_none(clip.get('playCount')), | |
128 | 'like_count': int_or_none(clip.get('likeCount')), | |
129 | 'comment_count': int_or_none(clip.get('commentCount')), | |
130 | 'formats': formats, | |
274bf5e4 | 131 | 'tags': clip.get('tagList'), |
f70ddd4a | 132 | } |