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.

70 lines
2.5 KiB

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