daum.py 4.9 KB

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