]>
Commit | Line | Data |
---|---|---|
4ffbf778 S |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
b78f5ec4 | 5 | from ..compat import compat_urllib_parse_unquote |
4ffbf778 S |
6 | from ..utils import ( |
7 | unified_strdate, | |
8 | int_or_none, | |
9 | qualities, | |
372744c5 | 10 | unescapeHTML, |
4ffbf778 S |
11 | ) |
12 | ||
13 | ||
14 | class OdnoklassnikiIE(InfoExtractor): | |
c6bbdadd | 15 | _VALID_URL = r'https?://(?:odnoklassniki|ok)\.ru/(?:video|web-api/video/moviePlayer)/(?P<id>[\d-]+)' |
4ffbf778 | 16 | _TESTS = [{ |
c6bbdadd | 17 | # metadata in JSON |
4ffbf778 S |
18 | 'url': 'http://ok.ru/video/20079905452', |
19 | 'md5': '8e24ad2da6f387948e7a7d44eb8668fe', | |
20 | 'info_dict': { | |
21 | 'id': '20079905452', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Культура меняет нас (прекрасный ролик!))', | |
24 | 'duration': 100, | |
4ffbf778 S |
25 | 'uploader_id': '330537914540', |
26 | 'uploader': 'Виталий Добровольский', | |
27 | 'like_count': int, | |
c6bbdadd S |
28 | }, |
29 | }, { | |
30 | # metadataUrl | |
31 | 'url': 'http://ok.ru/video/63567059965189-0', | |
32 | 'md5': '9676cf86eff5391d35dea675d224e131', | |
33 | 'info_dict': { | |
34 | 'id': '63567059965189-0', | |
35 | 'ext': 'mp4', | |
36 | 'title': 'Девушка без комплексов ...', | |
37 | 'duration': 191, | |
38 | 'uploader_id': '534380003155', | |
39 | 'uploader': 'Андрей Мещанинов', | |
40 | 'like_count': int, | |
4ffbf778 S |
41 | }, |
42 | }, { | |
43 | 'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452', | |
44 | 'only_matching': True, | |
45 | }] | |
46 | ||
47 | def _real_extract(self, url): | |
48 | video_id = self._match_id(url) | |
49 | ||
ba2df04b S |
50 | webpage = self._download_webpage( |
51 | 'http://ok.ru/video/%s' % video_id, video_id) | |
4ffbf778 S |
52 | |
53 | player = self._parse_json( | |
372744c5 S |
54 | unescapeHTML(self._search_regex( |
55 | r'data-attributes="([^"]+)"', webpage, 'player')), | |
4ffbf778 S |
56 | video_id) |
57 | ||
c6bbdadd S |
58 | flashvars = player['flashvars'] |
59 | ||
60 | metadata = flashvars.get('metadata') | |
61 | if metadata: | |
62 | metadata = self._parse_json(metadata, video_id) | |
63 | else: | |
64 | metadata = self._download_json( | |
b78f5ec4 | 65 | compat_urllib_parse_unquote(flashvars['metadataUrl']), |
c6bbdadd | 66 | video_id, 'Downloading metadata JSON') |
4ffbf778 S |
67 | |
68 | movie = metadata['movie'] | |
69 | title = movie['title'] | |
70 | thumbnail = movie.get('poster') | |
71 | duration = int_or_none(movie.get('duration')) | |
72 | ||
73 | author = metadata.get('author', {}) | |
74 | uploader_id = author.get('id') | |
75 | uploader = author.get('name') | |
76 | ||
77 | upload_date = unified_strdate(self._html_search_meta( | |
c6bbdadd | 78 | 'ya:ovs:upload_date', webpage, 'upload date', default=None)) |
4ffbf778 S |
79 | |
80 | age_limit = None | |
81 | adult = self._html_search_meta( | |
c6bbdadd | 82 | 'ya:ovs:adult', webpage, 'age limit', default=None) |
4ffbf778 S |
83 | if adult: |
84 | age_limit = 18 if adult == 'true' else 0 | |
85 | ||
86 | like_count = int_or_none(metadata.get('likeCount')) | |
87 | ||
88 | quality = qualities(('mobile', 'lowest', 'low', 'sd', 'hd')) | |
89 | ||
90 | formats = [{ | |
91 | 'url': f['url'], | |
92 | 'ext': 'mp4', | |
93 | 'format_id': f['name'], | |
94 | 'quality': quality(f['name']), | |
95 | } for f in metadata['videos']] | |
96 | ||
97 | return { | |
98 | 'id': video_id, | |
99 | 'title': title, | |
100 | 'thumbnail': thumbnail, | |
101 | 'duration': duration, | |
102 | 'upload_date': upload_date, | |
103 | 'uploader': uploader, | |
104 | 'uploader_id': uploader_id, | |
105 | 'like_count': like_count, | |
106 | 'age_limit': age_limit, | |
107 | 'formats': formats, | |
108 | } |