[wayofthemaster] Add extractor (Fixes #3575)
[youtube-dl] / youtube_dl / extractor / wayofthemaster.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import determine_ext
7
8
9 class WayOfTheMasterIE(InfoExtractor):
10     _VALID_URL = r'https?://www\.wayofthemaster\.com/([^/?#]*/)*(?P<id>[^/?#]+)\.s?html(?:$|[?#])'
11
12     _TEST = {
13         'url': 'http://www.wayofthemaster.com/hbks.shtml',
14         'md5': '5316b57487ada8480606a93cb3d18d24',
15         'info_dict': {
16             'id': 'hbks',
17             'ext': 'mp4',
18             'title': 'Intelligent Design vs. Evolution',
19         },
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         video_id = mobj.group('id')
25
26         webpage = self._download_webpage(url, video_id)
27
28         title = self._search_regex(
29             r'<img src="images/title_[^"]+".*?alt="([^"]+)"',
30             webpage, 'title', default=None)
31         if title is None:
32             title = self._html_search_regex(
33                 r'<title>(.*?)</title>', webpage, 'page title')
34
35         url_base = self._search_regex(
36             r'<param\s+name="?movie"?\s+value=".*?/wotm_videoplayer_highlow[0-9]*\.swf\?vid=([^"]+)"',
37             webpage, 'URL base')
38         formats = [{
39             'format_id': 'low',
40             'quality': 1,
41             'url': url_base + '_low.mp4',
42         }, {
43             'format_id': 'high',
44             'quality': 2,
45             'url': url_base + '_high.mp4',
46         }]
47         self._sort_formats(formats)
48
49         return {
50             'id': video_id,
51             'title': title,
52             'formats': formats,
53         }