2 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 class ScreenwaveMediaIE(InfoExtractor):
14 _VALID_URL = r'(?:http://)?(?' \
15 r':(?P<generic>player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=(?P<video_id>.+))' \
16 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>[^?#/]+))' \
17 r'|(?P<teamfourstar>(?:www\.)?teamfourstar\.com/video/(?P<tfs_display_id>[a-z0-9\-]+)/?)' \
22 'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
23 'md5': 'fde81fbafaee331785f58cd6c0d46190',
25 'id': 'Cinemasssacre-19911',
27 'upload_date': '20121110',
28 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
29 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
33 'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
34 'md5': 'd72f10cd39eac4215048f62ab477a511',
36 'id': 'Cinemasssacre-521be8ef82b16',
38 'upload_date': '20131002',
39 'title': 'The Mummy’s Hand (1940)',
44 def _cinemassacre_get_info(self, url):
45 mobj = re.match(self._VALID_URL, url)
46 display_id = mobj.group('cm_display_id')
48 webpage = self._download_webpage(url, display_id)
49 video_date = mobj.group('cm_date_Y') + mobj.group('cm_date_m') + mobj.group('cm_date_d')
50 mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"', webpage)
52 raise ExtractorError('Can\'t extract embed url and video id')
53 playerdata_url = mobj.group('embed_url')
55 video_title = self._html_search_regex(
56 r'<title>(?P<title>.+?)\|', webpage, 'title')
57 video_description = self._html_search_regex(
58 r'<div class="entry-content">(?P<description>.+?)</div>',
59 webpage, 'description', flags=re.DOTALL, fatal=False)
60 video_thumbnail = self._og_search_thumbnail(webpage)
64 'description': video_description,
65 'upload_date': video_date,
66 'thumbnail': video_thumbnail,
67 '_embed_url': playerdata_url,
70 def _teamfourstar_get_info(self, url):
71 mobj = re.match(self._VALID_URL, url)
72 display_id = mobj.group('tfs_display_id')
73 webpage = self._download_webpage(url, display_id)
75 mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"', webpage)
77 raise ExtractorError('Can\'t extract embed url and video id')
78 playerdata_url = mobj.group('embed_url')
80 video_title = self._html_search_regex(
81 r'<div class="heroheadingtitle">(?P<title>.+?)</div>', webpage, 'title')
82 video_date = self._html_search_regex(
83 r'<div class="heroheadingdate">(?P<date>.+?)</div>', webpage, 'date')
84 mobj = re.match('(?P<month>[A-Z][a-z]+) (?P<day>\d+), (?P<year>\d+)', video_date)
85 video_date = '%04u%02u%02u' % (int(mobj.group('year')), month_by_name(mobj.group('month')), int(mobj.group('day')))
86 video_description = self._html_search_regex(
87 r'<div class="postcontent">(?P<description>.+?)</div>', webpage, 'description', flags=re.DOTALL)
88 video_thumbnail = self._og_search_thumbnail(webpage)
92 'description': video_description,
93 'upload_date': video_date,
94 'thumbnail': video_thumbnail,
95 '_embed_url': playerdata_url,
98 def _screenwavemedia_get_info(self, url):
99 mobj = re.match(self._VALID_URL, url)
101 raise ExtractorError('Can\'t extract embed url and video id')
102 video_id = mobj.group('video_id')
104 playerdata = self._download_webpage(url, video_id, 'Downloading player webpage')
106 vidtitle = self._search_regex(
107 r'\'vidtitle\'\s*:\s*"([^\']+)"', playerdata, 'vidtitle').replace('\\/', '/')
108 vidurl = self._search_regex(
109 r'\'vidurl\'\s*:\s*"([^\']+)"', playerdata, 'vidurl').replace('\\/', '/')
110 pageurl = self._search_regex(
111 r'\'pageurl\'\s*:\s*"([^\']+)"', playerdata, 'pageurl', fatal=False).replace('\\/', '/')
115 mobj = re.search(r"'videoserver'\s*:\s*'(?P<videoserver>[^']+)'", playerdata)
117 videoserver = mobj.group('videoserver')
118 mobj = re.search(r'\'vidid\'\s*:\s*"(?P<vidid>[^\']+)"', playerdata)
119 vidid = mobj.group('vidid') if mobj else video_id
120 videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
122 mobj = re.search(r"file\s*:\s*'(?P<smil>http.+?/jwplayer\.smil)'", playerdata)
124 videolist_url = mobj.group('smil')
127 videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
129 baseurl = vidurl[:vidurl.rfind('/') + 1]
130 for video in videolist.findall('.//video'):
131 src = video.get('src')
134 file_ = src.partition(':')[-1]
135 width = int_or_none(video.get('width'))
136 height = int_or_none(video.get('height'))
137 bitrate = int_or_none(video.get('system-bitrate'))
139 'url': baseurl + file_,
140 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
144 'tbr': bitrate // 1000 if bitrate else None,
150 'abr': bitrate // 1000 if bitrate else None,
153 formats.append(format)
154 self._sort_formats(formats)
164 '_episode_page': pageurl,
167 def _real_extract(self, url):
168 mobj = re.match(self._VALID_URL, url)
173 if mobj.group('generic'):
174 swm_info = self._screenwavemedia_get_info(url)
175 url = swm_info['_episode_page']
176 mobj = re.match(self._VALID_URL, url)
179 if mobj.group('cinemassacre'):
180 site_info = self._cinemassacre_get_info(url)
181 elif mobj.group('teamfourstar'):
182 site_info = self._teamfourstar_get_info(url)
186 swm_info = self._screenwavemedia_get_info(site_info['_embed_url'])
189 raise ExtractorError("Failed to extract metadata for this URL")
192 swm_info.update(site_info)