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.

105 lines
4.0 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=(?: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. video_title = self._html_search_regex(
  45. r'<title>(?P<title>.+?)\|', webpage, 'title')
  46. video_description = self._html_search_regex(
  47. r'<div class="entry-content">(?P<description>.+?)</div>',
  48. webpage, 'description', flags=re.DOTALL, fatal=False)
  49. video_thumbnail = self._og_search_thumbnail(webpage)
  50. playerdata = self._download_webpage(playerdata_url, video_id, 'Downloading player webpage')
  51. vidurl = self._search_regex(
  52. r'\'vidurl\'\s*:\s*"([^\']+)"', playerdata, 'vidurl').replace('\\/', '/')
  53. vidid = self._search_regex(
  54. r'\'vidid\'\s*:\s*"([^\']+)"', playerdata, 'vidid')
  55. videoserver = self._html_search_regex(
  56. r"'videoserver'\s*:\s*'([^']+)'", playerdata, 'videoserver')
  57. videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
  58. videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
  59. formats = []
  60. baseurl = vidurl[:vidurl.rfind('/')+1]
  61. for video in videolist.findall('.//video'):
  62. src = video.get('src')
  63. if not src:
  64. continue
  65. file_ = src.partition(':')[-1]
  66. width = int_or_none(video.get('width'))
  67. height = int_or_none(video.get('height'))
  68. bitrate = int_or_none(video.get('system-bitrate'))
  69. format = {
  70. 'url': baseurl + file_,
  71. 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
  72. }
  73. if width or height:
  74. format.update({
  75. 'tbr': bitrate // 1000 if bitrate else None,
  76. 'width': width,
  77. 'height': height,
  78. })
  79. else:
  80. format.update({
  81. 'abr': bitrate // 1000 if bitrate else None,
  82. 'vcodec': 'none',
  83. })
  84. formats.append(format)
  85. self._sort_formats(formats)
  86. return {
  87. 'id': video_id,
  88. 'title': video_title,
  89. 'formats': formats,
  90. 'description': video_description,
  91. 'upload_date': video_date,
  92. 'thumbnail': video_thumbnail,
  93. }