Merge branch 'ceskatelevizesrt' of https://github.com/oskar456/youtube-dl into oskar4...
[youtube-dl] / youtube_dl / extractor / auengine.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import compat_urllib_parse
7 from ..utils import (
8     determine_ext,
9     ExtractorError,
10     remove_end,
11 )
12
13
14 class AUEngineIE(InfoExtractor):
15     _VALID_URL = r'http://(?:www\.)?auengine\.com/embed\.php\?.*?file=(?P<id>[^&]+).*?'
16
17     _TEST = {
18         'url': 'http://auengine.com/embed.php?file=lfvlytY6&w=650&h=370',
19         'md5': '48972bdbcf1a3a2f5533e62425b41d4f',
20         'info_dict': {
21             'id': 'lfvlytY6',
22             'ext': 'mp4',
23             'title': '[Commie]The Legend of the Legendary Heroes - 03 - Replication Eye (Alpha Stigma)[F9410F5A]'
24         }
25     }
26
27     def _real_extract(self, url):
28         video_id = self._match_id(url)
29
30         webpage = self._download_webpage(url, video_id)
31         title = self._html_search_regex(
32             r'<title>\s*(?P<title>.+?)\s*</title>', webpage, 'title')
33         video_urls = re.findall(r'http://\w+.auengine.com/vod/.*[^\W]', webpage)
34         video_url = compat_urllib_parse.unquote(video_urls[0])
35         thumbnails = re.findall(r'http://\w+.auengine.com/thumb/.*[^\W]', webpage)
36         thumbnail = compat_urllib_parse.unquote(thumbnails[0])
37
38         if not video_url:
39             raise ExtractorError('Could not find video URL')
40
41         ext = '.' + determine_ext(video_url)
42         title = remove_end(title, ext)
43
44         return {
45             'id': video_id,
46             'url': video_url,
47             'title': title,
48             'thumbnail': thumbnail,
49             'http_referer': 'http://www.auengine.com/flowplayer/flowplayer.commercial-3.2.14.swf',
50         }