[megavideozeu] Rename extractor
[youtube-dl] / youtube_dl / extractor / megavideoz.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     float_or_none,
9     xpath_text,
10 )
11
12
13 class MegaVideozIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?megavideoz\.eu/video/(?P<id>[^/]+)(?:/(?P<display_id>[^/]+))?'
15     _TEST = {
16         'url': 'http://megavideoz.eu/video/WM6UB919XMXH/SMPTE-Universal-Film-Leader',
17         'info_dict': {
18             'id': '48723',
19             'display_id': 'SMPTE-Universal-Film-Leader',
20             'ext': 'mp4',
21             'title': 'SMPTE Universal Film Leader',
22             'thumbnail': 're:https?://.*?\.jpg',
23             'duration': 10.93,
24         }
25     }
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('id')
30         display_id = mobj.group('display_id') or video_id
31
32         webpage = self._download_webpage(url, display_id)
33
34         config = self._download_xml(
35             self._search_regex(
36                 r"var\s+cnf\s*=\s*'([^']+)'", webpage, 'cnf url'),
37             display_id)
38
39         video_url = xpath_text(config, './file', 'video url', fatal=True)
40         title = xpath_text(config, './title', 'title', fatal=True)
41         thumbnail = xpath_text(config, './image', 'thumbnail')
42         duration = float_or_none(xpath_text(config, './duration', 'duration'))
43         video_id = xpath_text(config, './mediaid', 'video id') or video_id
44
45         return {
46             'id': video_id,
47             'display_id': display_id,
48             'url': video_url,
49             'title': title,
50             'thumbnail': thumbnail,
51             'duration': duration
52         }