2 from __future__ import unicode_literals
6 from .common import InfoExtractor
12 class ScreenwaveMediaIE(InfoExtractor):
13 _VALID_URL = r'(?:http://)?(?' \
14 r':(?P<generic>player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=(?P<video_id>.+))' \
15 r'|(?P<cinemassacre>(?:www\.)?cinemassacre\.com/(?P<cm_date_Y>[0-9]{4})/(?P<cm_date_m>[0-9]{2})/(?P<cm_date_d>[0-9]{2})/(?P<cm_display_id>[^?#/]+))' \
20 'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
21 'md5': 'fde81fbafaee331785f58cd6c0d46190',
23 'id': 'Cinemasssacre-19911',
25 'upload_date': '20121110',
26 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
27 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
31 'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
32 'md5': 'd72f10cd39eac4215048f62ab477a511',
34 'id': 'Cinemasssacre-521be8ef82b16',
36 'upload_date': '20131002',
37 'title': 'The Mummy’s Hand (1940)',
42 def _cinemassacre_get_info(self, url):
43 mobj = re.match(self._VALID_URL, url)
44 display_id = mobj.group('cm_display_id')
46 webpage = self._download_webpage(url, display_id)
47 video_date = mobj.group('cm_date_Y') + mobj.group('cm_date_m') + mobj.group('cm_date_d')
48 mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"', webpage)
50 raise ExtractorError('Can\'t extract embed url and video id')
51 playerdata_url = mobj.group('embed_url')
53 video_title = self._html_search_regex(
54 r'<title>(?P<title>.+?)\|', webpage, 'title')
55 video_description = self._html_search_regex(
56 r'<div class="entry-content">(?P<description>.+?)</div>',
57 webpage, 'description', flags=re.DOTALL, fatal=False)
58 video_thumbnail = self._og_search_thumbnail(webpage)
62 'description': video_description,
63 'upload_date': video_date,
64 'thumbnail': video_thumbnail,
65 '_embed_url': playerdata_url,
68 def _screenwavemedia_get_info(self, url):
69 mobj = re.match(self._VALID_URL, url)
71 raise ExtractorError('Can\'t extract embed url and video id')
72 video_id = mobj.group('video_id')
74 playerdata = self._download_webpage(url, video_id, 'Downloading player webpage')
76 vidtitle = self._search_regex(
77 r'\'vidtitle\'\s*:\s*"([^\']+)"', playerdata, 'vidtitle').replace('\\/', '/')
78 vidurl = self._search_regex(
79 r'\'vidurl\'\s*:\s*"([^\']+)"', playerdata, 'vidurl').replace('\\/', '/')
80 pageurl = self._search_regex(
81 r'\'pageurl\'\s*:\s*"([^\']+)"', playerdata, 'pageurl', fatal=False).replace('\\/', '/')
85 mobj = re.search(r"'videoserver'\s*:\s*'(?P<videoserver>[^']+)'", playerdata)
87 videoserver = mobj.group('videoserver')
88 mobj = re.search(r'\'vidid\'\s*:\s*"(?P<vidid>[^\']+)"', playerdata)
89 vidid = mobj.group('vidid') if mobj else video_id
90 videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
92 mobj = re.search(r"file\s*:\s*'(?P<smil>http.+?/jwplayer\.smil)'", playerdata)
94 videolist_url = mobj.group('smil')
97 videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
99 baseurl = vidurl[:vidurl.rfind('/') + 1]
100 for video in videolist.findall('.//video'):
101 src = video.get('src')
104 file_ = src.partition(':')[-1]
105 width = int_or_none(video.get('width'))
106 height = int_or_none(video.get('height'))
107 bitrate = int_or_none(video.get('system-bitrate'))
109 'url': baseurl + file_,
110 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
114 'tbr': bitrate // 1000 if bitrate else None,
120 'abr': bitrate // 1000 if bitrate else None,
123 formats.append(format)
124 self._sort_formats(formats)
134 '_episode_page': pageurl,
137 def _real_extract(self, url):
138 mobj = re.match(self._VALID_URL, url)
143 if mobj.group('generic'):
144 swm_info = self._screenwavemedia_get_info(url)
145 url = swm_info['_episode_page']
146 mobj = re.match(self._VALID_URL, url)
149 if mobj.group('cinemassacre'):
150 site_info = self._cinemassacre_get_info(url)
154 swm_info = self._screenwavemedia_get_info(site_info['_embed_url'])
157 raise ExtractorError("Failed to extract metadata for this URL")
160 swm_info.update(site_info)