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