2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
6 compat_etree_fromstring
,
8 compat_urllib_parse_unquote
,
9 compat_urllib_parse_urlparse
,
21 class OdnoklassnikiIE(InfoExtractor
):
22 _VALID_URL
= r
'https?://(?:(?:www|m|mobile)\.)?(?:odnoklassniki|ok)\.ru/(?:video(?:embed)?|web-api/video/moviePlayer)/(?P<id>[\d-]+)'
25 'url': 'http://ok.ru/video/20079905452',
26 'md5': '6ba728d85d60aa2e6dd37c9e70fdc6bc',
30 'title': 'Культура меняет нас (прекрасный ролик!))',
32 'upload_date': '20141207',
33 'uploader_id': '330537914540',
34 'uploader': 'Виталий Добровольский',
38 'skip': 'Video has been blocked',
41 'url': 'http://ok.ru/video/63567059965189-0?fromTime=5',
42 'md5': '6ff470ea2dd51d5d18c295a355b0b6bc',
44 'id': '63567059965189-0',
46 'title': 'Девушка без комплексов ...',
48 'upload_date': '20150518',
49 'uploader_id': '534380003155',
50 'uploader': '☭ Андрей Мещанинов ☭',
56 # YouTube embed (metadataUrl, provider == USER_YOUTUBE)
57 'url': 'http://ok.ru/video/64211978996595-1',
58 'md5': '2f206894ffb5dbfcce2c5a14b909eea5',
62 'title': 'Космическая среда от 26 августа 2015',
63 'description': 'md5:848eb8b85e5e3471a3a803dae1343ed0',
65 'upload_date': '20150826',
66 'uploader_id': 'tvroscosmos',
67 'uploader': 'Телестудия Роскосмоса',
71 # YouTube embed (metadata, provider == USER_YOUTUBE, no metadata.movie.title field)
72 'url': 'http://ok.ru/video/62036049272859-0',
74 'id': '62036049272859-0',
76 'title': 'МУЗЫКА ДОЖДЯ .',
77 'description': 'md5:6f1867132bd96e33bf53eda1091e8ed0',
78 'upload_date': '20120106',
79 'uploader_id': '473534735899',
80 'uploader': 'МARINA D',
84 'skip_download': True,
86 'skip': 'Video has not been found',
88 'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452',
89 'only_matching': True,
91 'url': 'http://www.ok.ru/video/20648036891',
92 'only_matching': True,
94 'url': 'http://www.ok.ru/videoembed/20648036891',
95 'only_matching': True,
97 'url': 'http://m.ok.ru/video/20079905452',
98 'only_matching': True,
100 'url': 'http://mobile.ok.ru/video/20079905452',
101 'only_matching': True,
104 def _real_extract(self
, url
):
105 start_time
= int_or_none(compat_parse_qs(
106 compat_urllib_parse_urlparse(url
).query
).get('fromTime', [None])[0])
108 video_id
= self
._match
_id
(url
)
110 webpage
= self
._download
_webpage
(
111 'http://ok.ru/video/%s' % video_id
, video_id
)
113 error
= self
._search
_regex
(
114 r
'[^>]+class="vp_video_stub_txt"[^>]*>([^<]+)<',
115 webpage
, 'error', default
=None)
117 raise ExtractorError(error
, expected
=True)
119 player
= self
._parse
_json
(
120 unescapeHTML(self
._search
_regex
(
121 r
'data-options=(?P<quote>["\'])(?P
<player
>{.+?
%s.+?
})(?P
=quote
)' % video_id,
122 webpage, 'player
', group='player
')),
125 flashvars = player['flashvars
']
127 metadata = flashvars.get('metadata
')
129 metadata = self._parse_json(metadata, video_id)
132 st_location = flashvars.get('location
')
134 data['st
.location
'] = st_location
135 metadata = self._download_json(
136 compat_urllib_parse_unquote(flashvars['metadataUrl
']),
137 video_id, 'Downloading metadata JSON
',
138 data=urlencode_postdata(data))
140 movie = metadata['movie
']
142 # Some embedded videos may not contain title in movie dict (e.g.
143 # http://ok.ru/video/62036049272859-0) thus we allow missing title
144 # here and it's going to be extracted later by an extractor that
145 # will process the actual embed.
146 provider
= metadata
.get('provider')
147 title
= movie
['title'] if provider
== 'UPLOADED_ODKL' else movie
.get('title')
149 thumbnail
= movie
.get('poster')
150 duration
= int_or_none(movie
.get('duration'))
152 author
= metadata
.get('author', {})
153 uploader_id
= author
.get('id')
154 uploader
= author
.get('name')
156 upload_date
= unified_strdate(self
._html
_search
_meta
(
157 'ya:ovs:upload_date', webpage
, 'upload date', default
=None))
160 adult
= self
._html
_search
_meta
(
161 'ya:ovs:adult', webpage
, 'age limit', default
=None)
163 age_limit
= 18 if adult
== 'true' else 0
165 like_count
= int_or_none(metadata
.get('likeCount'))
170 'thumbnail': thumbnail
,
171 'duration': duration
,
172 'upload_date': upload_date
,
173 'uploader': uploader
,
174 'uploader_id': uploader_id
,
175 'like_count': like_count
,
176 'age_limit': age_limit
,
177 'start_time': start_time
,
180 if provider
== 'USER_YOUTUBE':
182 '_type': 'url_transparent',
183 'url': movie
['contentId'],
187 quality
= qualities(('4', '0', '1', '2', '3', '5'))
192 'format_id': f
['name'],
193 } for f
in metadata
['videos']]
195 m3u8_url
= metadata
.get('hlsManifestUrl')
197 formats
.extend(self
._extract
_m
3u8_formats
(
198 m3u8_url
, video_id
, 'mp4', 'm3u8_native',
199 m3u8_id
='hls', fatal
=False))
201 dash_manifest
= metadata
.get('metadataEmbedded')
203 formats
.extend(self
._parse
_mpd
_formats
(
204 compat_etree_fromstring(dash_manifest
), 'mpd'))
207 fmt_type
= self
._search
_regex
(
208 r
'\btype[/=](\d)', fmt
['url'],
209 'format type', default
=None)
211 fmt
['quality'] = quality(fmt_type
)
213 self
._sort
_formats
(formats
)
215 info
['formats'] = formats