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