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.

153 lines
5.7 KiB

11 years ago
11 years ago
11 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse,
  7. compat_urllib_parse_unquote,
  8. )
  9. from ..utils import (
  10. int_or_none,
  11. str_to_int,
  12. xpath_text,
  13. )
  14. class DaumIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:(?:m\.)?tvpot\.daum\.net/v/|videofarm\.daum\.net/controller/player/VodPlayer\.swf\?vid=)(?P<id>[^?#&]+)'
  16. IE_NAME = 'daum.net'
  17. _TESTS = [{
  18. 'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
  19. 'info_dict': {
  20. 'id': 'vab4dyeDBysyBssyukBUjBz',
  21. 'ext': 'mp4',
  22. 'title': '마크 헌트 vs 안토니오 실바',
  23. 'description': 'Mark Hunt vs Antonio Silva',
  24. 'upload_date': '20131217',
  25. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  26. 'duration': 2117,
  27. 'view_count': int,
  28. 'comment_count': int,
  29. },
  30. }, {
  31. 'url': 'http://m.tvpot.daum.net/v/65139429',
  32. 'info_dict': {
  33. 'id': '65139429',
  34. 'ext': 'mp4',
  35. 'title': 'md5:a100d65d09cec246d8aa9bde7de45aed',
  36. 'description': 'md5:79794514261164ff27e36a21ad229fc5',
  37. 'upload_date': '20150604',
  38. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  39. 'duration': 154,
  40. 'view_count': int,
  41. 'comment_count': int,
  42. },
  43. }, {
  44. 'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://videofarm.daum.net/controller/player/VodPlayer.swf?vid=vwIpVpCQsT8%24&ref=',
  48. 'info_dict': {
  49. 'id': 'vwIpVpCQsT8$',
  50. 'ext': 'flv',
  51. 'title': '01-Korean War ( Trouble on the horizon )',
  52. 'description': '\nKorean War 01\nTrouble on the horizon\n전쟁의 먹구름',
  53. 'upload_date': '20080223',
  54. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  55. 'duration': 249,
  56. 'view_count': int,
  57. 'comment_count': int,
  58. },
  59. }]
  60. def _real_extract(self, url):
  61. video_id = compat_urllib_parse_unquote(self._match_id(url))
  62. query = compat_urllib_parse.urlencode({'vid': video_id})
  63. movie_data = self._download_json(
  64. 'http://videofarm.daum.net/controller/api/closed/v1_2/IntegratedMovieData.json?' + query,
  65. video_id, 'Downloading video formats info')
  66. # For urls like http://m.tvpot.daum.net/v/65139429, where the video_id is really a clipid
  67. if not movie_data.get('output_list', {}).get('output_list') and re.match(r'^\d+$', video_id):
  68. return self.url_result('http://tvpot.daum.net/clip/ClipView.do?clipid=%s' % video_id)
  69. info = self._download_xml(
  70. 'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
  71. 'Downloading video info')
  72. formats = []
  73. for format_el in movie_data['output_list']['output_list']:
  74. profile = format_el['profile']
  75. format_query = compat_urllib_parse.urlencode({
  76. 'vid': video_id,
  77. 'profile': profile,
  78. })
  79. url_doc = self._download_xml(
  80. 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
  81. video_id, note='Downloading video data for %s format' % profile)
  82. format_url = url_doc.find('result/url').text
  83. formats.append({
  84. 'url': format_url,
  85. 'format_id': profile,
  86. 'width': int_or_none(format_el.get('width')),
  87. 'height': int_or_none(format_el.get('height')),
  88. 'filesize': int_or_none(format_el.get('filesize')),
  89. })
  90. self._sort_formats(formats)
  91. return {
  92. 'id': video_id,
  93. 'title': info.find('TITLE').text,
  94. 'formats': formats,
  95. 'thumbnail': xpath_text(info, 'THUMB_URL'),
  96. 'description': xpath_text(info, 'CONTENTS'),
  97. 'duration': int_or_none(xpath_text(info, 'DURATION')),
  98. 'upload_date': info.find('REGDTTM').text[:8],
  99. 'view_count': str_to_int(xpath_text(info, 'PLAY_CNT')),
  100. 'comment_count': str_to_int(xpath_text(info, 'COMMENT_CNT')),
  101. }
  102. class DaumClipIE(InfoExtractor):
  103. _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:clip/ClipView.(?:do|tv)|mypot/View.do)\?.*?clipid=(?P<id>\d+)'
  104. IE_NAME = 'daum.net:clip'
  105. _TESTS = [{
  106. 'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
  107. 'info_dict': {
  108. 'id': '52554690',
  109. 'ext': 'mp4',
  110. 'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
  111. 'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
  112. 'upload_date': '20130831',
  113. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  114. 'duration': 3868,
  115. 'view_count': int,
  116. },
  117. }, {
  118. 'url': 'http://m.tvpot.daum.net/clip/ClipView.tv?clipid=54999425',
  119. 'only_matching': True,
  120. }]
  121. def _real_extract(self, url):
  122. video_id = self._match_id(url)
  123. clip_info = self._download_json(
  124. 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?clipid=%s' % video_id,
  125. video_id, 'Downloading clip info')['clip_bean']
  126. return {
  127. '_type': 'url_transparent',
  128. 'id': video_id,
  129. 'url': 'http://tvpot.daum.net/v/%s' % clip_info['vid'],
  130. 'title': clip_info['title'],
  131. 'thumbnail': clip_info.get('thumb_url'),
  132. 'description': clip_info.get('contents'),
  133. 'duration': int_or_none(clip_info.get('duration')),
  134. 'upload_date': clip_info.get('up_date')[:8],
  135. 'view_count': int_or_none(clip_info.get('play_count')),
  136. 'ie_key': 'Daum',
  137. }