Merge remote-tracking branch 'dstftw/macgamestore'
[youtube-dl] / youtube_dl / extractor / macgamestore.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import ExtractorError
5
6
7 class MacGameStoreIE(InfoExtractor):
8     IE_NAME = u'macgamestore'
9     IE_DESC = u'MacGameStore trailers'
10     _VALID_URL = r'https?://www\.macgamestore\.com/mediaviewer\.php\?trailer=(?P<id>\d+)'
11
12     _TEST = {
13         u'url': u'http://www.macgamestore.com/mediaviewer.php?trailer=2450',
14         u'file': u'2450.m4v',
15         u'md5': u'8649b8ea684b6666b4c5be736ecddc61',
16         u'info_dict': {
17             u'title': u'Crow',
18         }
19     }
20
21     def _real_extract(self, url):
22         mobj = re.match(self._VALID_URL, url)
23         video_id = mobj.group('id')
24         
25         webpage = self._download_webpage(url, video_id, u'Downloading trailer page')
26         
27         if re.search(r'>Missing Media<', webpage) is not None:
28             raise ExtractorError(u'Trailer %s does not exist' % video_id, expected=True)
29         
30         mobj = re.search(r'<title>MacGameStore: (?P<title>.*?) Trailer</title>', webpage)
31         video_title = mobj.group('title')
32         
33         mobj = re.search(r'(?s)<div\s+id="video-player".*?href="(?P<video>[^"]+)"\s*>', webpage)
34         video_url = mobj.group('video')
35         
36         return {
37             'id': video_id,
38             'url': video_url,
39             'title': video_title
40         }