[megavideoez] Add working test
[youtube-dl] / youtube_dl / extractor / megavideozeu.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     parse_filesize,
8     unified_strdate,
9 )
10
11
12 class MegavideozeuIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?megavideoz\.eu/video/(?P<id>.*)(?:.*)'
14     _TESTS = [
15         {
16             'url': 'http://megavideoz.eu/video/WM6UB919XMXH/SMPTE-Universal-Film-Leader',
17             'info_dict': {
18                 'id': '48723',
19                 'ext': 'mp4',
20                 'duration': '10',
21                 'title': 'SMPTE Universal Film Leader',
22             }
23         }
24     ]
25
26
27     def _real_extract(self, url):
28         tmp_video_id = self._match_id(url)
29
30         webpage = self._download_webpage(url, tmp_video_id)
31
32         config_php = self._html_search_regex(
33             r'var cnf = \'([^\']+)\'', webpage, 'config.php url')
34
35         configpage = self._download_webpage(config_php, tmp_video_id)
36
37         video_id = self._html_search_regex(
38             r'<mediaid>([^<]+)', configpage, 'video id')
39         video_url = self._html_search_regex(
40             r'<file>([^<]+)', configpage, 'video URL')
41         title = self._html_search_regex(
42             r'<title><!\[CDATA\[([^\]]+)', configpage, 'title')
43         duration = int_or_none(self._html_search_regex(
44             r'<duration>([0-9\.]+)', configpage, 'duration', fatal=False))
45
46         return {
47             'id': video_id,
48             'url': video_url,
49             'title': title,
50             'duration': duration
51         }