You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
5.4 KiB

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