You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
7.6 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. month_by_name,
  8. int_or_none,
  9. )
  10. class ScreenwaveMediaIE(InfoExtractor):
  11. _VALID_URL = r'(?:http://)?(?' \
  12. r':(?P<generic>player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=(?P<video_id>.+))' \
  13. 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>[^?#/]+))' \
  14. r'|(?P<teamfourstar>(?:www\.)?teamfourstar\.com/video/(?P<tfs_display_id>[a-z0-9\-]+)/?)' \
  15. r')'
  16. _TESTS = [
  17. {
  18. 'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
  19. 'md5': 'fde81fbafaee331785f58cd6c0d46190',
  20. 'info_dict': {
  21. 'id': 'Cinemasssacre-19911',
  22. 'ext': 'mp4',
  23. 'upload_date': '20121110',
  24. 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
  25. 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
  26. },
  27. },
  28. {
  29. 'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
  30. 'md5': 'd72f10cd39eac4215048f62ab477a511',
  31. 'info_dict': {
  32. 'id': 'Cinemasssacre-521be8ef82b16',
  33. 'ext': 'mp4',
  34. 'upload_date': '20131002',
  35. 'title': 'The Mummy’s Hand (1940)',
  36. },
  37. }
  38. ]
  39. def _cinemassacre_get_info(self, url):
  40. mobj = re.match(self._VALID_URL, url)
  41. display_id = mobj.group('cm_display_id')
  42. webpage = self._download_webpage(url, display_id)
  43. video_date = mobj.group('cm_date_Y') + mobj.group('cm_date_m') + mobj.group('cm_date_d')
  44. mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"', webpage)
  45. if not mobj:
  46. raise ExtractorError('Can\'t extract embed url and video id')
  47. playerdata_url = mobj.group('embed_url')
  48. video_title = self._html_search_regex(
  49. r'<title>(?P<title>.+?)\|', webpage, 'title')
  50. video_description = self._html_search_regex(
  51. r'<div class="entry-content">(?P<description>.+?)</div>',
  52. webpage, 'description', flags=re.DOTALL, fatal=False)
  53. video_thumbnail = self._og_search_thumbnail(webpage)
  54. return {
  55. 'title': video_title,
  56. 'description': video_description,
  57. 'upload_date': video_date,
  58. 'thumbnail': video_thumbnail,
  59. '_embed_url': playerdata_url,
  60. }
  61. def _teamfourstar_get_info(self, url):
  62. mobj = re.match(self._VALID_URL, url)
  63. display_id = mobj.group('tfs_display_id')
  64. webpage = self._download_webpage(url, display_id)
  65. mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=.+?)"', webpage)
  66. if not mobj:
  67. raise ExtractorError('Can\'t extract embed url and video id')
  68. playerdata_url = mobj.group('embed_url')
  69. video_title = self._html_search_regex(
  70. r'<div class="heroheadingtitle">(?P<title>.+?)</div>', webpage, 'title')
  71. video_date = self._html_search_regex(
  72. r'<div class="heroheadingdate">(?P<date>.+?)</div>', webpage, 'date')
  73. mobj = re.match('(?P<month>[A-Z][a-z]+) (?P<day>\d+), (?P<year>\d+)', video_date)
  74. video_date = '%04u%02u%02u' % (int(mobj.group('year')), month_by_name(mobj.group('month')), int(mobj.group('day')))
  75. video_description = self._html_search_regex(
  76. r'<div class="postcontent">(?P<description>.+?)</div>', webpage, 'description', flags=re.DOTALL)
  77. video_thumbnail = self._og_search_thumbnail(webpage)
  78. return {
  79. 'title': video_title,
  80. 'description': video_description,
  81. 'upload_date': video_date,
  82. 'thumbnail': video_thumbnail,
  83. '_embed_url': playerdata_url,
  84. }
  85. def _screenwavemedia_get_info(self, url):
  86. mobj = re.match(self._VALID_URL, url)
  87. if not mobj:
  88. raise ExtractorError('Can\'t extract embed url and video id')
  89. video_id = mobj.group('video_id')
  90. playerdata = self._download_webpage(url, video_id, 'Downloading player webpage')
  91. vidtitle = self._search_regex(
  92. r'\'vidtitle\'\s*:\s*"([^\']+)"', playerdata, 'vidtitle').replace('\\/', '/')
  93. vidurl = self._search_regex(
  94. r'\'vidurl\'\s*:\s*"([^\']+)"', playerdata, 'vidurl').replace('\\/', '/')
  95. pageurl = self._search_regex(
  96. r'\'pageurl\'\s*:\s*"([^\']+)"', playerdata, 'pageurl', fatal=False).replace('\\/', '/')
  97. videolist_url = None
  98. mobj = re.search(r"'videoserver'\s*:\s*'(?P<videoserver>[^']+)'", playerdata)
  99. if mobj:
  100. videoserver = mobj.group('videoserver')
  101. mobj = re.search(r'\'vidid\'\s*:\s*"(?P<vidid>[^\']+)"', playerdata)
  102. vidid = mobj.group('vidid') if mobj else video_id
  103. videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
  104. else:
  105. mobj = re.search(r"file\s*:\s*'(?P<smil>http.+?/jwplayer\.smil)'", playerdata)
  106. if mobj:
  107. videolist_url = mobj.group('smil')
  108. if videolist_url:
  109. videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
  110. formats = []
  111. baseurl = vidurl[:vidurl.rfind('/') + 1]
  112. for video in videolist.findall('.//video'):
  113. src = video.get('src')
  114. if not src:
  115. continue
  116. file_ = src.partition(':')[-1]
  117. width = int_or_none(video.get('width'))
  118. height = int_or_none(video.get('height'))
  119. bitrate = int_or_none(video.get('system-bitrate'))
  120. format = {
  121. 'url': baseurl + file_,
  122. 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
  123. }
  124. if width or height:
  125. format.update({
  126. 'tbr': bitrate // 1000 if bitrate else None,
  127. 'width': width,
  128. 'height': height,
  129. })
  130. else:
  131. format.update({
  132. 'abr': bitrate // 1000 if bitrate else None,
  133. 'vcodec': 'none',
  134. })
  135. formats.append(format)
  136. self._sort_formats(formats)
  137. else:
  138. formats = [{
  139. 'url': vidurl,
  140. }]
  141. return {
  142. 'id': video_id,
  143. 'title': vidtitle,
  144. 'formats': formats,
  145. '_episode_page': pageurl,
  146. }
  147. def _real_extract(self, url):
  148. mobj = re.match(self._VALID_URL, url)
  149. swm_info = None
  150. site_info = None
  151. if mobj.group('generic'):
  152. swm_info = self._screenwavemedia_get_info(url)
  153. url = swm_info['_episode_page']
  154. mobj = re.match(self._VALID_URL, url)
  155. if mobj:
  156. if mobj.group('cinemassacre'):
  157. site_info = self._cinemassacre_get_info(url)
  158. elif mobj.group('teamfourstar'):
  159. site_info = self._teamfourstar_get_info(url)
  160. if not swm_info:
  161. if site_info:
  162. swm_info = self._screenwavemedia_get_info(site_info['_embed_url'])
  163. if not swm_info:
  164. raise ExtractorError("Failed to extract metadata for this URL")
  165. if site_info:
  166. swm_info.update(site_info)
  167. return swm_info