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.

112 lines
4.1 KiB

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