]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/videa.py
debian/control: Update list of extractors in long description.
[youtubedl] / youtube_dl / extractor / videa.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 mimetype2ext,
10 parse_codecs,
11 xpath_element,
12 xpath_text,
13 )
14
15
16 class VideaIE(InfoExtractor):
17 _VALID_URL = r'''(?x)
18 https?://
19 videa(?:kid)?\.hu/
20 (?:
21 videok/(?:[^/]+/)*[^?#&]+-|
22 player\?.*?\bv=|
23 player/v/
24 )
25 (?P<id>[^?#&]+)
26 '''
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',
32 'ext': 'mp4',
33 'title': 'Az őrült kígyász 285 kígyót enged szabadon',
34 'thumbnail': r're:^https?://.*',
35 'duration': 21,
36 },
37 }, {
38 'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
39 'only_matching': True,
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,
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,
55 }]
56
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
63 def _real_extract(self, url):
64 video_id = self._match_id(url)
65
66 info = self._download_xml(
67 'http://videa.hu/videaplayer_get_xml.php', video_id,
68 query={'v': video_id})
69
70 video = xpath_element(info, './/video', 'video', fatal=True)
71 sources = xpath_element(info, './/video_sources', 'sources', fatal=True)
72
73 title = xpath_text(video, './title', fatal=True)
74
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)
90
91 thumbnail = xpath_text(video, './poster_src')
92 duration = int_or_none(xpath_text(video, './duration'))
93
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
98
99 return {
100 'id': video_id,
101 'title': title,
102 'thumbnail': thumbnail,
103 'duration': duration,
104 'age_limit': age_limit,
105 'formats': formats,
106 }