2 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class NaverIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:m\.)?tvcast\.naver\.com/v/(?P<id>\d+)'
21 'url': 'http://tvcast.naver.com/v/81652',
25 'title': '[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번',
26 'description': '합격불변의 법칙 메가스터디 | 메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.',
27 'upload_date': '20130903',
30 'url': 'http://tvcast.naver.com/v/395837',
31 'md5': '638ed4c12012c458fefcddfd01f173cd',
35 'title': '9년이 지나도 아픈 기억, 전효성의 아버지',
36 'description': 'md5:5bf200dcbf4b66eb1b350d1eb9c753f7',
37 'upload_date': '20150519',
39 'skip': 'Georestricted',
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44 webpage = self._download_webpage(url, video_id)
46 m_id = re.search(r'var rmcPlayer = new nhn.rmcnmv.RMCVideoPlayer\("(.+?)", "(.+?)"',
50 r'(?s)<div class="(?:nation_error|nation_box)">\s*(?:<!--.*?-->)?\s*<p class="[^"]+">(?P<msg>.+?)</p>\s*</div>',
53 raise ExtractorError(clean_html(m_error.group('msg')), expected=True)
54 raise ExtractorError('couldn\'t extract vid and key')
57 query = compat_urllib_parse.urlencode({'vid': vid, 'inKey': key, })
58 query_urls = compat_urllib_parse.urlencode({
63 info = self._download_xml(
64 'http://serviceapi.rmcnmv.naver.com/flash/videoInfo.nhn?' + query,
65 video_id, 'Downloading video info')
66 urls = self._download_xml(
67 'http://serviceapi.rmcnmv.naver.com/flash/playableEncodingOption.nhn?' + query_urls,
68 video_id, 'Downloading video formats info')
71 for format_el in urls.findall('EncodingOptions/EncodingOption'):
72 domain = format_el.find('Domain').text
73 uri = format_el.find('uri').text
75 'url': compat_urlparse.urljoin(domain, uri),
77 'width': int(format_el.find('width').text),
78 'height': int(format_el.find('height').text),
80 if domain.startswith('rtmp'):
81 # urlparse does not support custom schemes
82 # https://bugs.python.org/issue18828
86 'rtmp_protocol': '1', # rtmpt
89 self._sort_formats(formats)
93 'title': info.find('Subject').text,
95 'description': self._og_search_description(webpage),
96 'thumbnail': self._og_search_thumbnail(webpage),
97 'upload_date': info.find('WriteDate').text.replace('.', ''),
98 'view_count': int(info.find('PlayCount').text),