]>
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?:// | |
99c30918 | 19 | videa(?:kid)?\.hu/ |
69677f3e S |
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', | |
99c30918 | 34 | 'thumbnail': r're:^https?://.*', |
e7460215 B |
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, | |
99c30918 AMB |
46 | }, { |
47 | 'url': 'https://videakid.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH', | |
48 | 'only_matching': True, | |
49 | }, { | |
50 | 'url': 'https://videakid.hu/player?v=8YfIAjxwWGwT8HVQ', | |
51 | 'only_matching': True, | |
52 | }, { | |
53 | 'url': 'https://videakid.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1', | |
54 | 'only_matching': True, | |
e7460215 B |
55 | }] |
56 | ||
e186a9ec S |
57 | @staticmethod |
58 | def _extract_urls(webpage): | |
59 | return [url for _, url in re.findall( | |
60 | r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//videa\.hu/player\?.*?\bv=.+?)\1', | |
61 | webpage)] | |
62 | ||
e7460215 B |
63 | def _real_extract(self, url): |
64 | video_id = self._match_id(url) | |
65 | ||
69677f3e S |
66 | info = self._download_xml( |
67 | 'http://videa.hu/videaplayer_get_xml.php', video_id, | |
68 | query={'v': video_id}) | |
e7460215 | 69 | |
69677f3e S |
70 | video = xpath_element(info, './/video', 'video', fatal=True) |
71 | sources = xpath_element(info, './/video_sources', 'sources', fatal=True) | |
e7460215 | 72 | |
69677f3e | 73 | title = xpath_text(video, './title', fatal=True) |
e7460215 | 74 | |
69677f3e S |
75 | formats = [] |
76 | for source in sources.findall('./video_source'): | |
77 | source_url = source.text | |
78 | if not source_url: | |
79 | continue | |
80 | f = parse_codecs(source.get('codecs')) | |
81 | f.update({ | |
82 | 'url': source_url, | |
83 | 'ext': mimetype2ext(source.get('mimetype')) or 'mp4', | |
84 | 'format_id': source.get('name'), | |
85 | 'width': int_or_none(source.get('width')), | |
86 | 'height': int_or_none(source.get('height')), | |
87 | }) | |
88 | formats.append(f) | |
89 | self._sort_formats(formats) | |
e7460215 | 90 | |
69677f3e S |
91 | thumbnail = xpath_text(video, './poster_src') |
92 | duration = int_or_none(xpath_text(video, './duration')) | |
e7460215 | 93 | |
69677f3e S |
94 | age_limit = None |
95 | is_adult = xpath_text(video, './is_adult_content', default=None) | |
96 | if is_adult: | |
97 | age_limit = 18 if is_adult == '1' else 0 | |
e7460215 | 98 | |
69677f3e S |
99 | return { |
100 | 'id': video_id, | |
101 | 'title': title, | |
102 | 'thumbnail': thumbnail, | |
103 | 'duration': duration, | |
104 | 'age_limit': age_limit, | |
105 | 'formats': formats, | |
106 | } |