aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/wayofthemaster.py
blob: af7bb8b492a3bc731d95be4235a84d642e19cfa9 (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
from __future__ import unicode_literals

import re

from .common import InfoExtractor


class WayOfTheMasterIE(InfoExtractor):
    _VALID_URL = r'https?://www\.wayofthemaster\.com/([^/?#]*/)*(?P<id>[^/?#]+)\.s?html(?:$|[?#])'

    _TEST = {
        'url': 'http://www.wayofthemaster.com/hbks.shtml',
        'md5': '5316b57487ada8480606a93cb3d18d24',
        'info_dict': {
            'id': 'hbks',
            'ext': 'mp4',
            'title': 'Intelligent Design vs. Evolution',
        },
    }

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

        webpage = self._download_webpage(url, video_id)

        title = self._search_regex(
            r'<img src="images/title_[^"]+".*?alt="([^"]+)"',
            webpage, 'title', default=None)
        if title is None:
            title = self._html_search_regex(
                r'<title>(.*?)</title>', webpage, 'page title')

        url_base = self._search_regex(
            r'<param\s+name="?movie"?\s+value=".*?/wotm_videoplayer_highlow[0-9]*\.swf\?vid=([^"]+)"',
            webpage, 'URL base')
        formats = [{
            'format_id': 'low',
            'quality': 1,
            'url': url_base + '_low.mp4',
        }, {
            'format_id': 'high',
            'quality': 2,
            'url': url_base + '_high.mp4',
        }]
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': title,
            'formats': formats,
        }