Merge remote-tracking branch 'Rudloff/websurg'
[youtube-dl] / youtube_dl / extractor / cinemassacre.py
1 # encoding: utf-8
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6     ExtractorError,
7 )
8
9
10 class CinemassacreIE(InfoExtractor):
11     _VALID_URL = r'(?:http://)?(?:www\.)?(?P<url>cinemassacre\.com/(?P<date_Y>[0-9]{4})/(?P<date_m>[0-9]{2})/(?P<date_d>[0-9]{2})/.+?)(?:[/?].*)?'
12     _TESTS = [{
13         u'url': u'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
14         u'file': u'19911.flv',
15         u'info_dict': {
16             u'upload_date': u'20121110',
17             u'title': u'“Angry Video Game Nerd: The Movie” – Trailer',
18             u'description': u'md5:fb87405fcb42a331742a0dce2708560b',
19         },
20         u'params': {
21             # rtmp download
22             u'skip_download': True,
23         },
24     },
25     {
26         u'url': u'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
27         u'file': u'521be8ef82b16.flv',
28         u'info_dict': {
29             u'upload_date': u'20131002',
30             u'title': u'The Mummy’s Hand (1940)',
31         },
32         u'params': {
33             # rtmp download
34             u'skip_download': True,
35         },
36     }]
37
38     def _real_extract(self, url):
39         mobj = re.match(self._VALID_URL, url)
40
41         webpage_url = u'http://' + mobj.group('url')
42         webpage = self._download_webpage(webpage_url, None) # Don't know video id yet
43         video_date = mobj.group('date_Y') + mobj.group('date_m') + mobj.group('date_d')
44         mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/(?:embed|player)\.php\?id=(?:Cinemassacre-)?(?P<video_id>.+?))"', webpage)
45         if not mobj:
46             raise ExtractorError(u'Can\'t extract embed url and video id')
47         playerdata_url = mobj.group(u'embed_url')
48         video_id = mobj.group(u'video_id')
49
50         video_title = self._html_search_regex(r'<title>(?P<title>.+?)\|',
51             webpage, u'title')
52         video_description = self._html_search_regex(r'<div class="entry-content">(?P<description>.+?)</div>',
53             webpage, u'description', flags=re.DOTALL, fatal=False)
54         if len(video_description) == 0:
55             video_description = None
56
57         playerdata = self._download_webpage(playerdata_url, video_id)
58         base_url = self._html_search_regex(r'\'streamer\': \'(?P<base_url>rtmp://.*?)/(?:vod|Cinemassacre)\'',
59             playerdata, u'base_url')
60         base_url += '/Cinemassacre/'
61         # Important: The file names in playerdata are not used by the player and even wrong for some videos
62         sd_file = 'Cinemassacre-%s_high.mp4' % video_id
63         hd_file = 'Cinemassacre-%s.mp4' % video_id
64         video_thumbnail = 'http://image.screenwavemedia.com/Cinemassacre/Cinemassacre-%s_thumb_640x360.jpg' % video_id
65
66         formats = [
67             {
68                 'url': base_url + sd_file,
69                 'ext': 'flv',
70                 'format': 'sd',
71                 'format_id': 'sd',
72             },
73             {
74                 'url': base_url + hd_file,
75                 'ext': 'flv',
76                 'format': 'hd',
77                 'format_id': 'hd',
78             },
79         ]
80
81         info = {
82             'id': video_id,
83             'title': video_title,
84             'formats': formats,
85             'description': video_description,
86             'upload_date': video_date,
87             'thumbnail': video_thumbnail,
88         }
89         # TODO: Remove when #980 has been merged
90         info.update(formats[-1])
91         return info