3 import xml.etree.ElementTree
5 from .common import InfoExtractor
12 class NaverIE(InfoExtractor):
13 _VALID_URL = r'https?://tvcast\.naver\.com/v/(?P<id>\d+)'
16 u'url': u'http://tvcast.naver.com/v/81652',
17 u'file': u'81652.mp4',
19 u'title': u'[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번',
20 u'description': u'합격불변의 법칙 메가스터디 | 메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.',
21 u'upload_date': u'20130903',
25 def _real_extract(self, url):
26 mobj = re.match(self._VALID_URL, url)
27 video_id = mobj.group(1)
28 webpage = self._download_webpage(url, video_id)
29 m_id = re.search(r'var rmcPlayer = new nhn.rmcnmv.RMCVideoPlayer\("(.+?)", "(.+?)"',
32 raise ExtractorError(u'couldn\'t extract vid and key')
35 query = compat_urllib_parse.urlencode({'vid': vid, 'inKey': key,})
36 query_urls = compat_urllib_parse.urlencode({
41 info_xml = self._download_webpage(
42 'http://serviceapi.rmcnmv.naver.com/flash/videoInfo.nhn?' + query,
43 video_id, u'Downloading video info')
44 urls_xml = self._download_webpage(
45 'http://serviceapi.rmcnmv.naver.com/flash/playableEncodingOption.nhn?' + query_urls,
46 video_id, u'Downloading video formats info')
47 info = xml.etree.ElementTree.fromstring(info_xml.encode('utf-8'))
48 urls = xml.etree.ElementTree.fromstring(urls_xml.encode('utf-8'))
51 for format_el in urls.findall('EncodingOptions/EncodingOption'):
52 domain = format_el.find('Domain').text
53 if domain.startswith('rtmp'):
56 'url': domain + format_el.find('uri').text,
58 'width': int(format_el.find('width').text),
59 'height': int(format_el.find('height').text),
64 'title': info.find('Subject').text,
66 'description': self._og_search_description(webpage),
67 'thumbnail': self._og_search_thumbnail(webpage),
68 'upload_date': info.find('WriteDate').text.replace('.', ''),
69 'view_count': int(info.find('PlayCount').text),
71 # TODO: Remove when #980 has been merged
72 info.update(formats[-1])