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.

74 lines
2.8 KiB

  1. # encoding: utf-8
  2. import re
  3. import xml.etree.ElementTree
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse,
  7. determine_ext,
  8. )
  9. class DaumIE(InfoExtractor):
  10. _VALID_URL = r'https?://tvpot\.daum\.net/.*?clipid=(?P<id>\d+)'
  11. IE_NAME = u'daum.net'
  12. _TEST = {
  13. u'url': u'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
  14. u'file': u'52554690.mp4',
  15. u'info_dict': {
  16. u'title': u'DOTA 2GETHER 시즌2 6회 - 2부',
  17. u'description': u'DOTA 2GETHER 시즌2 6회 - 2부',
  18. u'upload_date': u'20130831',
  19. u'duration': 3868,
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group(1)
  25. canonical_url = 'http://tvpot.daum.net/v/%s' % video_id
  26. webpage = self._download_webpage(canonical_url, video_id)
  27. full_id = self._search_regex(r'<link rel="video_src" href=".+?vid=(.+?)"',
  28. webpage, u'full id')
  29. query = compat_urllib_parse.urlencode({'vid': full_id})
  30. info_xml = self._download_webpage(
  31. 'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
  32. u'Downloading video info')
  33. urls_xml = self._download_webpage(
  34. 'http://videofarm.daum.net/controller/api/open/v1_2/MovieData.apixml?' + query,
  35. video_id, u'Downloading video formats info')
  36. info = xml.etree.ElementTree.fromstring(info_xml.encode('utf-8'))
  37. urls = xml.etree.ElementTree.fromstring(urls_xml.encode('utf-8'))
  38. self.to_screen(u'%s: Getting video urls' % video_id)
  39. formats = []
  40. for format_el in urls.findall('result/output_list/output_list'):
  41. profile = format_el.attrib['profile']
  42. format_query = compat_urllib_parse.urlencode({
  43. 'vid': full_id,
  44. 'profile': profile,
  45. })
  46. url_xml = self._download_webpage(
  47. 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
  48. video_id, note=False)
  49. url_doc = xml.etree.ElementTree.fromstring(url_xml.encode('utf-8'))
  50. format_url = url_doc.find('result/url').text
  51. formats.append({
  52. 'url': format_url,
  53. 'ext': determine_ext(format_url),
  54. 'format_id': profile,
  55. })
  56. info = {
  57. 'id': video_id,
  58. 'title': info.find('TITLE').text,
  59. 'formats': formats,
  60. 'thumbnail': self._og_search_thumbnail(webpage),
  61. 'description': info.find('CONTENTS').text,
  62. 'duration': int(info.find('DURATION').text),
  63. 'upload_date': info.find('REGDTTM').text[:8],
  64. }
  65. # TODO: Remove when #980 has been merged
  66. info.update(formats[-1])
  67. return info