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.

118 lines
4.5 KiB

  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. int_or_none,
  8. )
  9. class CinemassacreIE(InfoExtractor):
  10. _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})/(?P<display_id>[^?#/]+)'
  11. _TESTS = [
  12. {
  13. 'url': 'http://cinemassacre.com/2012/11/10/avgn-the-movie-trailer/',
  14. 'md5': 'fde81fbafaee331785f58cd6c0d46190',
  15. 'info_dict': {
  16. 'id': '19911',
  17. 'ext': 'mp4',
  18. 'upload_date': '20121110',
  19. 'title': '“Angry Video Game Nerd: The Movie” – Trailer',
  20. 'description': 'md5:fb87405fcb42a331742a0dce2708560b',
  21. },
  22. },
  23. {
  24. 'url': 'http://cinemassacre.com/2013/10/02/the-mummys-hand-1940',
  25. 'md5': 'd72f10cd39eac4215048f62ab477a511',
  26. 'info_dict': {
  27. 'id': '521be8ef82b16',
  28. 'ext': 'mp4',
  29. 'upload_date': '20131002',
  30. 'title': 'The Mummy’s Hand (1940)',
  31. },
  32. }
  33. ]
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. display_id = mobj.group('display_id')
  37. webpage = self._download_webpage(url, display_id)
  38. video_date = mobj.group('date_Y') + mobj.group('date_m') + mobj.group('date_d')
  39. mobj = re.search(r'src="(?P<embed_url>http://player\.screenwavemedia\.com/play/[a-zA-Z]+\.php\?[^"]*\bid=(?P<full_video_id>(?:Cinemassacre-)?(?P<video_id>.+?)))"', webpage)
  40. if not mobj:
  41. raise ExtractorError('Can\'t extract embed url and video id')
  42. playerdata_url = mobj.group('embed_url')
  43. video_id = mobj.group('video_id')
  44. full_video_id = mobj.group('full_video_id')
  45. video_title = self._html_search_regex(
  46. r'<title>(?P<title>.+?)\|', webpage, 'title')
  47. video_description = self._html_search_regex(
  48. r'<div class="entry-content">(?P<description>.+?)</div>',
  49. webpage, 'description', flags=re.DOTALL, fatal=False)
  50. video_thumbnail = self._og_search_thumbnail(webpage)
  51. playerdata = self._download_webpage(playerdata_url, video_id, 'Downloading player webpage')
  52. vidurl = self._search_regex(
  53. r'\'vidurl\'\s*:\s*"([^\']+)"', playerdata, 'vidurl').replace('\\/', '/')
  54. videolist_url = None
  55. mobj = re.search(r"'videoserver'\s*:\s*'(?P<videoserver>[^']+)'", playerdata)
  56. if mobj:
  57. videoserver = mobj.group('videoserver')
  58. mobj = re.search(r'\'vidid\'\s*:\s*"(?P<vidid>[^\']+)"', playerdata)
  59. vidid = mobj.group('vidid') if mobj else full_video_id
  60. videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
  61. else:
  62. mobj = re.search(r"file\s*:\s*'(?P<smil>http.+?/jwplayer\.smil)'", playerdata)
  63. if mobj:
  64. videolist_url = mobj.group('smil')
  65. if videolist_url:
  66. videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
  67. formats = []
  68. baseurl = vidurl[:vidurl.rfind('/')+1]
  69. for video in videolist.findall('.//video'):
  70. src = video.get('src')
  71. if not src:
  72. continue
  73. file_ = src.partition(':')[-1]
  74. width = int_or_none(video.get('width'))
  75. height = int_or_none(video.get('height'))
  76. bitrate = int_or_none(video.get('system-bitrate'))
  77. format = {
  78. 'url': baseurl + file_,
  79. 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
  80. }
  81. if width or height:
  82. format.update({
  83. 'tbr': bitrate // 1000 if bitrate else None,
  84. 'width': width,
  85. 'height': height,
  86. })
  87. else:
  88. format.update({
  89. 'abr': bitrate // 1000 if bitrate else None,
  90. 'vcodec': 'none',
  91. })
  92. formats.append(format)
  93. self._sort_formats(formats)
  94. else:
  95. formats = [{
  96. 'url': vidurl,
  97. }]
  98. return {
  99. 'id': video_id,
  100. 'title': video_title,
  101. 'formats': formats,
  102. 'description': video_description,
  103. 'upload_date': video_date,
  104. 'thumbnail': video_thumbnail,
  105. }