2 from __future__ import unicode_literals
4 from .common import InfoExtractor
7 compat_urllib_parse_unquote,
8 compat_urllib_parse_urlparse,
19 class OdnoklassnikiIE(InfoExtractor):
20 _VALID_URL = r'https?://(?:(?:www|m|mobile)\.)?(?:odnoklassniki|ok)\.ru/(?:video(?:embed)?|web-api/video/moviePlayer)/(?P<id>[\d-]+)'
23 'url': 'http://ok.ru/video/20079905452',
24 'md5': '6ba728d85d60aa2e6dd37c9e70fdc6bc',
28 'title': 'Культура меняет нас (прекрасный ролик!))',
30 'upload_date': '20141207',
31 'uploader_id': '330537914540',
32 'uploader': 'Виталий Добровольский',
36 'skip': 'Video has been blocked',
39 'url': 'http://ok.ru/video/63567059965189-0?fromTime=5',
40 'md5': '9676cf86eff5391d35dea675d224e131',
42 'id': '63567059965189-0',
44 'title': 'Девушка без комплексов ...',
46 'upload_date': '20150518',
47 'uploader_id': '534380003155',
48 'uploader': '☭ Андрей Мещанинов ☭',
54 # YouTube embed (metadataUrl, provider == USER_YOUTUBE)
55 'url': 'http://ok.ru/video/64211978996595-1',
56 'md5': '5d7475d428845cd2e13bae6f1a992278',
58 'id': '64211978996595-1',
60 'title': 'Космическая среда от 26 августа 2015',
61 'description': 'md5:848eb8b85e5e3471a3a803dae1343ed0',
63 'upload_date': '20150826',
64 'uploader_id': '750099571',
65 'uploader': 'Алина П',
69 # YouTube embed (metadata, provider == USER_YOUTUBE, no metadata.movie.title field)
70 'url': 'http://ok.ru/video/62036049272859-0',
72 'id': '62036049272859-0',
74 'title': 'МУЗЫКА ДОЖДЯ .',
75 'description': 'md5:6f1867132bd96e33bf53eda1091e8ed0',
76 'upload_date': '20120106',
77 'uploader_id': '473534735899',
78 'uploader': 'МARINA D',
82 'skip_download': True,
85 'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452',
86 'only_matching': True,
88 'url': 'http://www.ok.ru/video/20648036891',
89 'only_matching': True,
91 'url': 'http://www.ok.ru/videoembed/20648036891',
92 'only_matching': True,
94 'url': 'http://m.ok.ru/video/20079905452',
95 'only_matching': True,
97 'url': 'http://mobile.ok.ru/video/20079905452',
98 'only_matching': True,
101 def _real_extract(self, url):
102 start_time = int_or_none(compat_parse_qs(
103 compat_urllib_parse_urlparse(url).query).get('fromTime', [None])[0])
105 video_id = self._match_id(url)
107 webpage = self._download_webpage(
108 'http://ok.ru/video/%s' % video_id, video_id)
110 error = self._search_regex(
111 r'[^>]+class="vp_video_stub_txt"[^>]*>([^<]+)<',
112 webpage, 'error', default=None)
114 raise ExtractorError(error, expected=True)
116 player = self._parse_json(
117 unescapeHTML(self._search_regex(
118 r'data-options=(?P<quote>["\'])(?P<player>{.+?%s.+?})(?P=quote)' % video_id,
119 webpage, 'player', group='player')),
122 flashvars = player['flashvars']
124 metadata = flashvars.get('metadata')
126 metadata = self._parse_json(metadata, video_id)
128 metadata = self._download_json(
129 compat_urllib_parse_unquote(flashvars['metadataUrl']),
130 video_id, 'Downloading metadata JSON')
132 movie = metadata['movie']
134 # Some embedded videos may not contain title in movie dict (e.g.
135 # http://ok.ru/video/62036049272859-0) thus we allow missing title
136 # here and it's going to be extracted later by an extractor that
137 # will process the actual embed.
138 provider = metadata.get('provider')
139 title = movie['title'] if provider == 'UPLOADED_ODKL' else movie.get('title')
141 thumbnail = movie.get('poster')
142 duration = int_or_none(movie.get('duration'))
144 author = metadata.get('author', {})
145 uploader_id = author.get('id')
146 uploader = author.get('name')
148 upload_date = unified_strdate(self._html_search_meta(
149 'ya:ovs:upload_date', webpage, 'upload date', default=None))
152 adult = self._html_search_meta(
153 'ya:ovs:adult', webpage, 'age limit', default=None)
155 age_limit = 18 if adult == 'true' else 0
157 like_count = int_or_none(metadata.get('likeCount'))
162 'thumbnail': thumbnail,
163 'duration': duration,
164 'upload_date': upload_date,
165 'uploader': uploader,
166 'uploader_id': uploader_id,
167 'like_count': like_count,
168 'age_limit': age_limit,
169 'start_time': start_time,
172 if provider == 'USER_YOUTUBE':
174 '_type': 'url_transparent',
175 'url': movie['contentId'],
179 quality = qualities(('mobile', 'lowest', 'low', 'sd', 'hd'))
184 'format_id': f['name'],
185 'quality': quality(f['name']),
186 } for f in metadata['videos']]
187 self._sort_formats(formats)
189 info['formats'] = formats