]>
Commit | Line | Data |
---|---|---|
e7460215 B |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
e186a9ec S |
4 | import re |
5 | ||
e7460215 B |
6 | from .common import InfoExtractor |
7 | from ..utils import ( | |
8 | int_or_none, | |
69677f3e S |
9 | mimetype2ext, |
10 | parse_codecs, | |
e7460215 B |
11 | xpath_element, |
12 | xpath_text, | |
e7460215 B |
13 | ) |
14 | ||
15 | ||
16 | class VideaIE(InfoExtractor): | |
69677f3e S |
17 | _VALID_URL = r'''(?x) |
18 | https?:// | |
19 | videa\.hu/ | |
20 | (?: | |
21 | videok/(?:[^/]+/)*[^?#&]+-| | |
22 | player\?.*?\bv=| | |
23 | player/v/ | |
24 | ) | |
25 | (?P<id>[^?#&]+) | |
26 | ''' | |
e7460215 B |
27 | _TESTS = [{ |
28 | 'url': 'http://videa.hu/videok/allatok/az-orult-kigyasz-285-kigyot-kigyo-8YfIAjxwWGwT8HVQ', | |
29 | 'md5': '97a7af41faeaffd9f1fc864a7c7e7603', | |
30 | 'info_dict': { | |
31 | 'id': '8YfIAjxwWGwT8HVQ', | |
e7460215 B |
32 | 'ext': 'mp4', |
33 | 'title': 'Az őrült kígyász 285 kígyót enged szabadon', | |
34 | 'thumbnail': 'http://videa.hu/static/still/1.4.1.1007274.1204470.3', | |
35 | 'duration': 21, | |
36 | }, | |
37 | }, { | |
38 | 'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH', | |
39 | 'only_matching': True, | |
69677f3e S |
40 | }, { |
41 | 'url': 'http://videa.hu/player?v=8YfIAjxwWGwT8HVQ', | |
42 | 'only_matching': True, | |
43 | }, { | |
44 | 'url': 'http://videa.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1', | |
45 | 'only_matching': True, | |
e7460215 B |
46 | }] |
47 | ||
e186a9ec S |
48 | @staticmethod |
49 | def _extract_urls(webpage): | |
50 | return [url for _, url in re.findall( | |
51 | r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//videa\.hu/player\?.*?\bv=.+?)\1', | |
52 | webpage)] | |
53 | ||
e7460215 B |
54 | def _real_extract(self, url): |
55 | video_id = self._match_id(url) | |
56 | ||
69677f3e S |
57 | info = self._download_xml( |
58 | 'http://videa.hu/videaplayer_get_xml.php', video_id, | |
59 | query={'v': video_id}) | |
e7460215 | 60 | |
69677f3e S |
61 | video = xpath_element(info, './/video', 'video', fatal=True) |
62 | sources = xpath_element(info, './/video_sources', 'sources', fatal=True) | |
e7460215 | 63 | |
69677f3e | 64 | title = xpath_text(video, './title', fatal=True) |
e7460215 | 65 | |
69677f3e S |
66 | formats = [] |
67 | for source in sources.findall('./video_source'): | |
68 | source_url = source.text | |
69 | if not source_url: | |
70 | continue | |
71 | f = parse_codecs(source.get('codecs')) | |
72 | f.update({ | |
73 | 'url': source_url, | |
74 | 'ext': mimetype2ext(source.get('mimetype')) or 'mp4', | |
75 | 'format_id': source.get('name'), | |
76 | 'width': int_or_none(source.get('width')), | |
77 | 'height': int_or_none(source.get('height')), | |
78 | }) | |
79 | formats.append(f) | |
80 | self._sort_formats(formats) | |
e7460215 | 81 | |
69677f3e S |
82 | thumbnail = xpath_text(video, './poster_src') |
83 | duration = int_or_none(xpath_text(video, './duration')) | |
e7460215 | 84 | |
69677f3e S |
85 | age_limit = None |
86 | is_adult = xpath_text(video, './is_adult_content', default=None) | |
87 | if is_adult: | |
88 | age_limit = 18 if is_adult == '1' else 0 | |
e7460215 | 89 | |
69677f3e S |
90 | return { |
91 | 'id': video_id, | |
92 | 'title': title, | |
93 | 'thumbnail': thumbnail, | |
94 | 'duration': duration, | |
95 | 'age_limit': age_limit, | |
96 | 'formats': formats, | |
97 | } |