]>
Commit | Line | Data |
---|---|---|
6b95b065 | 1 | # encoding: utf-8 |
24da5893 JMF |
2 | from __future__ import unicode_literals |
3 | ||
6b95b065 | 4 | import re |
6b95b065 JMF |
5 | |
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | compat_urllib_parse, | |
9 | ExtractorError, | |
10 | ) | |
11 | ||
12 | ||
13 | class NaverIE(InfoExtractor): | |
24b173fa | 14 | _VALID_URL = r'https?://(?:m\.)?tvcast\.naver\.com/v/(?P<id>\d+)' |
6b95b065 JMF |
15 | |
16 | _TEST = { | |
24da5893 JMF |
17 | 'url': 'http://tvcast.naver.com/v/81652', |
18 | 'info_dict': { | |
19 | 'id': '81652', | |
20 | 'ext': 'mp4', | |
21 | 'title': '[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번', | |
22 | 'description': '합격불변의 법칙 메가스터디 | 메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.', | |
23 | 'upload_date': '20130903', | |
6b95b065 JMF |
24 | }, |
25 | } | |
26 | ||
27 | def _real_extract(self, url): | |
28 | mobj = re.match(self._VALID_URL, url) | |
29 | video_id = mobj.group(1) | |
30 | webpage = self._download_webpage(url, video_id) | |
31 | m_id = re.search(r'var rmcPlayer = new nhn.rmcnmv.RMCVideoPlayer\("(.+?)", "(.+?)"', | |
32 | webpage) | |
33 | if m_id is None: | |
24da5893 | 34 | raise ExtractorError('couldn\'t extract vid and key') |
6b95b065 JMF |
35 | vid = m_id.group(1) |
36 | key = m_id.group(2) | |
37 | query = compat_urllib_parse.urlencode({'vid': vid, 'inKey': key,}) | |
38 | query_urls = compat_urllib_parse.urlencode({ | |
39 | 'masterVid': vid, | |
40 | 'protocol': 'p2p', | |
41 | 'inKey': key, | |
42 | }) | |
e26f8712 | 43 | info = self._download_xml( |
6b95b065 | 44 | 'http://serviceapi.rmcnmv.naver.com/flash/videoInfo.nhn?' + query, |
24da5893 | 45 | video_id, 'Downloading video info') |
e26f8712 | 46 | urls = self._download_xml( |
6b95b065 | 47 | 'http://serviceapi.rmcnmv.naver.com/flash/playableEncodingOption.nhn?' + query_urls, |
24da5893 | 48 | video_id, 'Downloading video formats info') |
6b95b065 JMF |
49 | |
50 | formats = [] | |
51 | for format_el in urls.findall('EncodingOptions/EncodingOption'): | |
52 | domain = format_el.find('Domain').text | |
087ca2cb | 53 | f = { |
6b95b065 JMF |
54 | 'url': domain + format_el.find('uri').text, |
55 | 'ext': 'mp4', | |
56 | 'width': int(format_el.find('width').text), | |
57 | 'height': int(format_el.find('height').text), | |
087ca2cb JMF |
58 | } |
59 | if domain.startswith('rtmp'): | |
60 | f.update({ | |
61 | 'ext': 'flv', | |
62 | 'rtmp_protocol': '1', # rtmpt | |
63 | }) | |
64 | formats.append(f) | |
65 | self._sort_formats(formats) | |
6b95b065 | 66 | |
fb7abb31 | 67 | return { |
6b95b065 JMF |
68 | 'id': video_id, |
69 | 'title': info.find('Subject').text, | |
70 | 'formats': formats, | |
71 | 'description': self._og_search_description(webpage), | |
72 | 'thumbnail': self._og_search_thumbnail(webpage), | |
73 | 'upload_date': info.find('WriteDate').text.replace('.', ''), | |
74 | 'view_count': int(info.find('PlayCount').text), | |
75 | } |