]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/megavideoz.py
debian/changelog: Initiate a new release.
[youtubedl] / 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 ExtractorError,
9 float_or_none,
10 xpath_text,
11 )
12
13
14 class MegaVideozIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?megavideoz\.eu/video/(?P<id>[^/]+)(?:/(?P<display_id>[^/]+))?'
16 _TEST = {
17 'url': 'http://megavideoz.eu/video/WM6UB919XMXH/SMPTE-Universal-Film-Leader',
18 'info_dict': {
19 'id': '48723',
20 'display_id': 'SMPTE-Universal-Film-Leader',
21 'ext': 'mp4',
22 'title': 'SMPTE Universal Film Leader',
23 'thumbnail': 're:https?://.*?\.jpg',
24 'duration': 10.93,
25 }
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
31 display_id = mobj.group('display_id') or video_id
32
33 webpage = self._download_webpage(url, display_id)
34
35 if any(p in webpage for p in ('>Video Not Found<', '>404 Error<')):
36 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
37
38 config = self._download_xml(
39 self._search_regex(
40 r"var\s+cnf\s*=\s*'([^']+)'", webpage, 'cnf url'),
41 display_id)
42
43 video_url = xpath_text(config, './file', 'video url', fatal=True)
44 title = xpath_text(config, './title', 'title', fatal=True)
45 thumbnail = xpath_text(config, './image', 'thumbnail')
46 duration = float_or_none(xpath_text(config, './duration', 'duration'))
47 video_id = xpath_text(config, './mediaid', 'video id') or video_id
48
49 return {
50 'id': video_id,
51 'display_id': display_id,
52 'url': video_url,
53 'title': title,
54 'thumbnail': thumbnail,
55 'duration': duration
56 }