2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse_unquote
15 class OdnoklassnikiIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?(?:odnoklassniki|ok)\.ru/(?:video|web-api/video/moviePlayer)/(?P<id>[\d-]+)'
19 'url': 'http://ok.ru/video/20079905452',
20 'md5': '6ba728d85d60aa2e6dd37c9e70fdc6bc',
24 'title': 'Культура меняет нас (прекрасный ролик!))',
26 'upload_date': '20141207',
27 'uploader_id': '330537914540',
28 'uploader': 'Виталий Добровольский',
32 'skip': 'Video has been blocked',
35 'url': 'http://ok.ru/video/63567059965189-0',
36 'md5': '9676cf86eff5391d35dea675d224e131',
38 'id': '63567059965189-0',
40 'title': 'Девушка без комплексов ...',
42 'upload_date': '20150518',
43 'uploader_id': '534380003155',
44 'uploader': '☭ Андрей Мещанинов ☭',
49 # YouTube embed (metadataUrl, provider == USER_YOUTUBE)
50 'url': 'http://ok.ru/video/64211978996595-1',
51 'md5': '5d7475d428845cd2e13bae6f1a992278',
53 'id': '64211978996595-1',
55 'title': 'Космическая среда от 26 августа 2015',
56 'description': 'md5:848eb8b85e5e3471a3a803dae1343ed0',
58 'upload_date': '20150826',
59 'uploader_id': '750099571',
60 'uploader': 'Алина П',
64 'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452',
65 'only_matching': True,
67 'url': 'http://www.ok.ru/video/20648036891',
68 'only_matching': True,
71 def _real_extract(self, url):
72 video_id = self._match_id(url)
74 webpage = self._download_webpage(
75 'http://ok.ru/video/%s' % video_id, video_id)
77 error = self._search_regex(
78 r'[^>]+class="vp_video_stub_txt"[^>]*>([^<]+)<',
79 webpage, 'error', default=None)
81 raise ExtractorError(error, expected=True)
83 player = self._parse_json(
84 unescapeHTML(self._search_regex(
85 r'data-options=(?P<quote>["\'])(?P<player>{.+?%s.+?})(?P=quote)' % video_id,
86 webpage, 'player', group='player')),
89 flashvars = player['flashvars']
91 metadata = flashvars.get('metadata')
93 metadata = self._parse_json(metadata, video_id)
95 metadata = self._download_json(
96 compat_urllib_parse_unquote(flashvars['metadataUrl']),
97 video_id, 'Downloading metadata JSON')
99 movie = metadata['movie']
100 title = movie['title']
101 thumbnail = movie.get('poster')
102 duration = int_or_none(movie.get('duration'))
104 author = metadata.get('author', {})
105 uploader_id = author.get('id')
106 uploader = author.get('name')
108 upload_date = unified_strdate(self._html_search_meta(
109 'ya:ovs:upload_date', webpage, 'upload date', default=None))
112 adult = self._html_search_meta(
113 'ya:ovs:adult', webpage, 'age limit', default=None)
115 age_limit = 18 if adult == 'true' else 0
117 like_count = int_or_none(metadata.get('likeCount'))
122 'thumbnail': thumbnail,
123 'duration': duration,
124 'upload_date': upload_date,
125 'uploader': uploader,
126 'uploader_id': uploader_id,
127 'like_count': like_count,
128 'age_limit': age_limit,
131 if metadata.get('provider') == 'USER_YOUTUBE':
133 '_type': 'url_transparent',
134 'url': movie['contentId'],
138 quality = qualities(('mobile', 'lowest', 'low', 'sd', 'hd'))
143 'format_id': f['name'],
144 'quality': quality(f['name']),
145 } for f in metadata['videos']]
146 self._sort_formats(formats)
148 info['formats'] = formats