40ea5ec95f89f8d20ac8eb0b81350a7c5c14440b
[youtube-dl] / youtube_dl / extractor / auengine.py
1 import os.path
2 import re
3 import urllib
4 import urlparse
5
6 from .common import InfoExtractor
7
8 class AuengineIE(InfoExtractor):
9     _VALID_URL = r'(?:http://)?(?:www\.)?auengine\.com/embed.php\?.*?file=([^&]+).*?'
10
11     def _real_extract(self, url):
12         mobj = re.match(self._VALID_URL, url)
13         video_id = mobj.group(1)
14         webpage = self._download_webpage(url, video_id)
15         title = self._html_search_regex(r'<title>(?P<title>.+?)</title>',
16                 webpage, u'title')
17         title = title.strip()
18         links = re.findall(r'[^A-Za-z0-9]?(?:file|url):\s*["\'](http[^\'"&]*)', webpage)
19         links = [urllib.unquote(l) for l in links]
20         for link in links:
21             root, pathext = os.path.splitext(urlparse.urlparse(link).path)
22             if pathext == '.png':
23                 thumbnail = link
24             elif pathext == '.mp4':
25                 url = link
26                 ext = pathext
27         if ext == title[-len(ext):]:
28             title = title[:-len(ext)]
29         ext = ext[1:]
30         return [{
31             'id':        video_id,
32             'url':       url,
33             'ext':       ext,
34             'title':     title,
35             'thumbnail': thumbnail,
36         }]