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.

100 lines
3.8 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\?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. 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. playerdata = self._download_webpage(playerdata_url, video_id, 'Downloading player webpage')
  50. video_thumbnail = self._search_regex(
  51. r'image: \'(?P<thumbnail>[^\']+)\'', playerdata, 'thumbnail', fatal=False)
  52. sd_url = self._search_regex(r'file: \'([^\']+)\', label: \'SD\'', playerdata, 'sd_file')
  53. videolist_url = self._search_regex(r'file: \'([^\']+\.smil)\'}', playerdata, 'videolist_url')
  54. videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
  55. formats = []
  56. baseurl = sd_url[:sd_url.rfind('/')+1]
  57. for video in videolist.findall('.//video'):
  58. src = video.get('src')
  59. if not src:
  60. continue
  61. file_ = src.partition(':')[-1]
  62. width = int_or_none(video.get('width'))
  63. height = int_or_none(video.get('height'))
  64. bitrate = int_or_none(video.get('system-bitrate'))
  65. format = {
  66. 'url': baseurl + file_,
  67. 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
  68. }
  69. if width or height:
  70. format.update({
  71. 'tbr': bitrate // 1000 if bitrate else None,
  72. 'width': width,
  73. 'height': height,
  74. })
  75. else:
  76. format.update({
  77. 'abr': bitrate // 1000 if bitrate else None,
  78. 'vcodec': 'none',
  79. })
  80. formats.append(format)
  81. self._sort_formats(formats)
  82. return {
  83. 'id': video_id,
  84. 'title': video_title,
  85. 'formats': formats,
  86. 'description': video_description,
  87. 'upload_date': video_date,
  88. 'thumbnail': video_thumbnail,
  89. }