]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cinemassacre.py
debian/control: Update list of extractors.
[youtubedl] / 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/[a-zA-Z]+\.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 url = self._html_search_regex(r'\'streamer\': \'(?P<url>[^\']+)\'', playerdata, u'url')
59
60 sd_file = self._html_search_regex(r'\'file\': \'(?P<sd_file>[^\']+)\'', playerdata, u'sd_file')
61 hd_file = self._html_search_regex(r'\'?file\'?: "(?P<hd_file>[^"]+)"', playerdata, u'hd_file')
62 video_thumbnail = self._html_search_regex(r'\'image\': \'(?P<thumbnail>[^\']+)\'', playerdata, u'thumbnail', fatal=False)
63
64 formats = [
65 {
66 'url': url,
67 'play_path': 'mp4:' + sd_file,
68 'rtmp_live': True, # workaround
69 'ext': 'flv',
70 'format': 'sd',
71 'format_id': 'sd',
72 },
73 {
74 'url': url,
75 'play_path': 'mp4:' + hd_file,
76 'rtmp_live': True, # workaround
77 'ext': 'flv',
78 'format': 'hd',
79 'format_id': 'hd',
80 },
81 ]
82
83 return {
84 'id': video_id,
85 'title': video_title,
86 'formats': formats,
87 'description': video_description,
88 'upload_date': video_date,
89 'thumbnail': video_thumbnail,
90 }