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.

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