Revert "Workaround for regex engine limitation"
[youtube-dl] / youtube_dl / extractor / cinemassacre.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     ExtractorError,
8 )
9
10
11 class CinemassacreIE(InfoExtractor):
12     _VALID_URL = r'http://(?:www\.)?cinemassacre\.com/(?P<date_Y>[0-9]{4})/(?P<date_m>[0-9]{2})/(?P<date_d>[0-9]{2})/.+?'
13     _TESTS = [
14         {
15             'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
16             'file': '19911.mp4',
17             'md5': 'fde81fbafaee331785f58cd6c0d46190',
18             'info_dict': {
19                 'upload_date': '20121110',
20                 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
21                 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
22             },
23         },
24         {
25             'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
26             'file': '521be8ef82b16.mp4',
27             'md5': 'd72f10cd39eac4215048f62ab477a511',
28             'info_dict': {
29                 'upload_date': '20131002',
30                 'title': 'The Mummy’s Hand (1940)',
31             },
32         }
33     ]
34
35     def _real_extract(self, url):
36         mobj = re.match(self._VALID_URL, url)
37
38         webpage = self._download_webpage(url, None)  # Don't know video id yet
39         video_date = mobj.group('date_Y') + mobj.group('date_m') + mobj.group('date_d')
40         mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?id=(?:Cinemassacre-)?(?P<video_id>.+?))"', webpage)
41         if not mobj:
42             raise ExtractorError('Can\'t extract embed url and video id')
43         playerdata_url = mobj.group('embed_url')
44         video_id = mobj.group('video_id')
45
46         video_title = self._html_search_regex(r'<title>(?P<title>.+?)\|',
47             webpage, 'title')
48         video_description = self._html_search_regex(r'<div class="entry-content">(?P<description>.+?)</div>',
49             webpage, 'description', flags=re.DOTALL, fatal=False)
50         if len(video_description) == 0:
51             video_description = None
52
53         playerdata = self._download_webpage(playerdata_url, video_id)
54
55         sd_url = self._html_search_regex(r'file: \'(?P<sd_file>[^\']+)\', label: \'SD\'', playerdata, 'sd_file')
56         hd_url = self._html_search_regex(r'file: \'(?P<hd_file>[^\']+)\', label: \'HD\'', playerdata, 'hd_file')
57         video_thumbnail = self._html_search_regex(r'image: \'(?P<thumbnail>[^\']+)\'', playerdata, 'thumbnail', fatal=False)
58
59         formats = [
60             {
61                 'url': sd_url,
62                 'ext': 'mp4',
63                 'format': 'sd',
64                 'format_id': 'sd',
65             },
66             {
67                 'url': hd_url,
68                 'ext': 'mp4',
69                 'format': 'hd',
70                 'format_id': 'hd',
71             },
72         ]
73
74         return {
75             'id': video_id,
76             'title': video_title,
77             'formats': formats,
78             'description': video_description,
79             'upload_date': video_date,
80             'thumbnail': video_thumbnail,
81         }