aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/megavideoz.py
blob: af7ff07ea1e5818c3e0c94511328fd26c2458657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# encoding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    xpath_text,
)


class MegaVideozIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?megavideoz\.eu/video/(?P<id>[^/]+)(?:/(?P<display_id>[^/]+))?'
    _TEST = {
        'url': 'http://megavideoz.eu/video/WM6UB919XMXH/SMPTE-Universal-Film-Leader',
        'info_dict': {
            'id': '48723',
            'display_id': 'SMPTE-Universal-Film-Leader',
            'ext': 'mp4',
            'title': 'SMPTE Universal Film Leader',
            'thumbnail': 're:https?://.*?\.jpg',
            'duration': 10.93,
        }
    }

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_id = mobj.group('id')
        display_id = mobj.group('display_id') or video_id

        webpage = self._download_webpage(url, display_id)

        if any(p in webpage for p in ('>Video Not Found<', '>404 Error<')):
            raise ExtractorError('Video %s does not exist' % video_id, expected=True)

        config = self._download_xml(
            self._search_regex(
                r"var\s+cnf\s*=\s*'([^']+)'", webpage, 'cnf url'),
            display_id)

        video_url = xpath_text(config, './file', 'video url', fatal=True)
        title = xpath_text(config, './title', 'title', fatal=True)
        thumbnail = xpath_text(config, './image', 'thumbnail')
        duration = float_or_none(xpath_text(config, './duration', 'duration'))
        video_id = xpath_text(config, './mediaid', 'video id') or video_id

        return {
            'id': video_id,
            'display_id': display_id,
            'url': video_url,
            'title': title,
            'thumbnail': thumbnail,
            'duration': duration
        }