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.

89 lines
3.3 KiB

11 years ago
11 years ago
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. )
  8. class DaumIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:v/|.*?clipid=)(?P<id>[^?#&]+)'
  10. IE_NAME = 'daum.net'
  11. _TESTS = [{
  12. 'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
  13. 'info_dict': {
  14. 'id': '52554690',
  15. 'ext': 'mp4',
  16. 'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
  17. 'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
  18. 'upload_date': '20130831',
  19. 'duration': 3868,
  20. },
  21. }, {
  22. # Test for https://github.com/rg3/youtube-dl/issues/7949
  23. 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=M1O35s8HPOo0&clipid=73147290',
  24. 'md5': 'c92d78bcee4424451f1667f275c1dc97',
  25. 'info_dict': {
  26. 'id': '73147290',
  27. 'ext': 'mp4',
  28. 'title': '싸이 - 나팔바지 [유희열의 스케치북] 299회 20151218',
  29. 'description': '싸이 - 나팔바지',
  30. 'upload_date': '20151219',
  31. 'duration': 232,
  32. },
  33. }, {
  34. 'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. mobj = re.match(self._VALID_URL, url)
  42. video_id = mobj.group('id')
  43. canonical_url = 'http://tvpot.daum.net/v/%s' % video_id
  44. webpage = self._download_webpage(canonical_url, video_id)
  45. og_url = self._og_search_url(webpage, default=None) or self._search_regex(
  46. r'<link[^>]+rel=(["\'])canonical\1[^>]+href=(["\'])(?P<url>.+?)\2',
  47. webpage, 'canonical url', group='url')
  48. full_id = self._search_regex(
  49. r'tvpot\.daum\.net/v/([^/]+)', og_url, 'full id')
  50. query = compat_urllib_parse.urlencode({'vid': full_id})
  51. info = self._download_xml(
  52. 'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
  53. 'Downloading video info')
  54. urls = self._download_xml(
  55. 'http://videofarm.daum.net/controller/api/open/v1_2/MovieData.apixml?' + query,
  56. video_id, 'Downloading video formats info')
  57. formats = []
  58. for format_el in urls.findall('result/output_list/output_list'):
  59. profile = format_el.attrib['profile']
  60. format_query = compat_urllib_parse.urlencode({
  61. 'vid': full_id,
  62. 'profile': profile,
  63. })
  64. url_doc = self._download_xml(
  65. 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
  66. video_id, note='Downloading video data for %s format' % profile)
  67. format_url = url_doc.find('result/url').text
  68. formats.append({
  69. 'url': format_url,
  70. 'format_id': profile,
  71. })
  72. return {
  73. 'id': video_id,
  74. 'title': info.find('TITLE').text,
  75. 'formats': formats,
  76. 'thumbnail': self._og_search_thumbnail(webpage),
  77. 'description': info.find('CONTENTS').text,
  78. 'duration': int(info.find('DURATION').text),
  79. 'upload_date': info.find('REGDTTM').text[:8],
  80. }