]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/naver.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class NaverIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:m\.)?tvcast\.naver\.com/v/(?P<id>\d+)'
18 'url': 'http://tvcast.naver.com/v/81652',
22 'title': '[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번',
23 'description': '합격불변의 법칙 메가스터디 | 메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.',
24 'upload_date': '20130903',
27 'url': 'http://tvcast.naver.com/v/395837',
28 'md5': '638ed4c12012c458fefcddfd01f173cd',
32 'title': '9년이 지나도 아픈 기억, 전효성의 아버지',
33 'description': 'md5:5bf200dcbf4b66eb1b350d1eb9c753f7',
34 'upload_date': '20150519',
36 'skip': 'Georestricted',
39 def _real_extract(self
, url
):
40 video_id
= self
._match
_id
(url
)
41 webpage
= self
._download
_webpage
(url
, video_id
)
43 m_id
= re
.search(r
'var rmcPlayer = new nhn.rmcnmv.RMCVideoPlayer\("(.+?)", "(.+?)"',
46 error
= self
._html
_search
_regex
(
47 r
'(?s)<div class="(?:nation_error|nation_box|error_box)">\s*(?:<!--.*?-->)?\s*<p class="[^"]+">(?P<msg>.+?)</p>\s*</div>',
48 webpage
, 'error', default
=None)
50 raise ExtractorError(error
, expected
=True)
51 raise ExtractorError('couldn\'t extract vid and key')
52 video_data
= self
._download
_json
(
53 'http://play.rmcnmv.naver.com/vod/play/v2.0/' + m_id
.group(1),
57 meta
= video_data
['meta']
58 title
= meta
['subject']
61 def extract_formats(streams
, stream_type
, query
={}):
62 for stream
in streams
:
63 stream_url
= stream
.get('source')
66 stream_url
= update_url_query(stream_url
, query
)
67 encoding_option
= stream
.get('encodingOption', {})
68 bitrate
= stream
.get('bitrate', {})
70 'format_id': '%s_%s' % (stream
.get('type') or stream_type
, encoding_option
.get('id') or encoding_option
.get('name')),
72 'width': int_or_none(encoding_option
.get('width')),
73 'height': int_or_none(encoding_option
.get('height')),
74 'vbr': int_or_none(bitrate
.get('video')),
75 'abr': int_or_none(bitrate
.get('audio')),
76 'filesize': int_or_none(stream
.get('size')),
77 'protocol': 'm3u8_native' if stream_type
== 'HLS' else None,
80 extract_formats(video_data
.get('videos', {}).get('list', []), 'H264')
81 for stream_set
in video_data
.get('streams', []):
83 for param
in stream_set
.get('keys', []):
84 query
[param
['name']] = param
['value']
85 stream_type
= stream_set
.get('type')
86 videos
= stream_set
.get('videos')
88 extract_formats(videos
, stream_type
, query
)
89 elif stream_type
== 'HLS':
90 stream_url
= stream_set
.get('source')
93 formats
.extend(self
._extract
_m
3u8_formats
(
94 update_url_query(stream_url
, query
), video_id
,
95 'mp4', 'm3u8_native', m3u8_id
=stream_type
, fatal
=False))
96 self
._sort
_formats
(formats
)
99 for caption
in video_data
.get('captions', {}).get('list', []):
100 caption_url
= caption
.get('source')
103 subtitles
.setdefault(caption
.get('language') or caption
.get('locale'), []).append({
107 upload_date
= self
._search
_regex
(
108 r
'<span[^>]+class="date".*?(\d{4}\.\d{2}\.\d{2})',
109 webpage
, 'upload date', fatal
=False)
111 upload_date
= upload_date
.replace('.', '')
117 'subtitles': subtitles
,
118 'description': self
._og
_search
_description
(webpage
),
119 'thumbnail': meta
.get('cover', {}).get('source') or self
._og
_search
_thumbnail
(webpage
),
120 'view_count': int_or_none(meta
.get('count')),
121 'upload_date': upload_date
,