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.

149 lines
6.1 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class LiveLeakIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<id>[\w_]+)(?:.*)'
  8. _TESTS = [{
  9. 'url': 'http://www.liveleak.com/view?i=757_1364311680',
  10. 'md5': '50f79e05ba149149c1b4ea961223d5b3',
  11. 'info_dict': {
  12. 'id': '757_1364311680',
  13. 'ext': 'flv',
  14. 'description': 'extremely bad day for this guy..!',
  15. 'uploader': 'ljfriel2',
  16. 'title': 'Most unlucky car accident',
  17. 'thumbnail': r're:^https?://.*\.jpg$'
  18. }
  19. }, {
  20. 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
  21. 'md5': 'b13a29626183c9d33944e6a04f41aafc',
  22. 'info_dict': {
  23. 'id': 'f93_1390833151',
  24. 'ext': 'mp4',
  25. 'description': 'German Television Channel NDR does an exclusive interview with Edward Snowden.\r\nUploaded on LiveLeak cause German Television thinks the rest of the world isn\'t intereseted in Edward Snowden.',
  26. 'uploader': 'ARD_Stinkt',
  27. 'title': 'German Television does first Edward Snowden Interview (ENGLISH)',
  28. 'thumbnail': r're:^https?://.*\.jpg$'
  29. }
  30. }, {
  31. 'url': 'http://www.liveleak.com/view?i=4f7_1392687779',
  32. 'md5': '42c6d97d54f1db107958760788c5f48f',
  33. 'info_dict': {
  34. 'id': '4f7_1392687779',
  35. 'ext': 'mp4',
  36. 'description': "The guy with the cigarette seems amazingly nonchalant about the whole thing... I really hope my friends' reactions would be a bit stronger.\r\n\r\nAction-go to 0:55.",
  37. 'uploader': 'CapObveus',
  38. 'title': 'Man is Fatally Struck by Reckless Car While Packing up a Moving Truck',
  39. 'age_limit': 18,
  40. }
  41. }, {
  42. # Covers https://github.com/rg3/youtube-dl/pull/5983
  43. 'url': 'http://www.liveleak.com/view?i=801_1409392012',
  44. 'md5': '0b3bec2d888c20728ca2ad3642f0ef15',
  45. 'info_dict': {
  46. 'id': '801_1409392012',
  47. 'ext': 'mp4',
  48. 'description': 'Happened on 27.7.2014. \r\nAt 0:53 you can see people still swimming at near beach.',
  49. 'uploader': 'bony333',
  50. 'title': 'Crazy Hungarian tourist films close call waterspout in Croatia',
  51. 'thumbnail': r're:^https?://.*\.jpg$'
  52. }
  53. }, {
  54. # Covers https://github.com/rg3/youtube-dl/pull/10664#issuecomment-247439521
  55. 'url': 'http://m.liveleak.com/view?i=763_1473349649',
  56. 'add_ie': ['Youtube'],
  57. 'info_dict': {
  58. 'id': '763_1473349649',
  59. 'ext': 'mp4',
  60. 'title': 'Reporters and public officials ignore epidemic of black on asian violence in Sacramento | Colin Flaherty',
  61. 'description': 'Colin being the warrior he is and showing the injustice Asians in Sacramento are being subjected to.',
  62. 'uploader': 'Ziz',
  63. 'upload_date': '20160908',
  64. 'uploader_id': 'UCEbta5E_jqlZmEJsriTEtnw'
  65. },
  66. 'params': {
  67. 'skip_download': True,
  68. },
  69. }]
  70. @staticmethod
  71. def _extract_url(webpage):
  72. mobj = re.search(
  73. r'<iframe[^>]+src="https?://(?:\w+\.)?liveleak\.com/ll_embed\?(?:.*?)i=(?P<id>[\w_]+)(?:.*)',
  74. webpage)
  75. if mobj:
  76. return 'http://www.liveleak.com/view?i=%s' % mobj.group('id')
  77. def _real_extract(self, url):
  78. video_id = self._match_id(url)
  79. webpage = self._download_webpage(url, video_id)
  80. video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip()
  81. video_description = self._og_search_description(webpage)
  82. video_uploader = self._html_search_regex(
  83. r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False)
  84. age_limit = int_or_none(self._search_regex(
  85. r'you confirm that you are ([0-9]+) years and over.',
  86. webpage, 'age limit', default=None))
  87. video_thumbnail = self._og_search_thumbnail(webpage)
  88. sources_raw = self._search_regex(
  89. r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None)
  90. if sources_raw is None:
  91. alt_source = self._search_regex(
  92. r'(file: ".*?"),', webpage, 'video URL', default=None)
  93. if alt_source:
  94. sources_raw = '[{ %s}]' % alt_source
  95. else:
  96. # Maybe an embed?
  97. embed_url = self._search_regex(
  98. r'<iframe[^>]+src="(https?://(?:www\.)?(?:prochan|youtube)\.com/embed[^"]+)"',
  99. webpage, 'embed URL')
  100. return {
  101. '_type': 'url_transparent',
  102. 'url': embed_url,
  103. 'id': video_id,
  104. 'title': video_title,
  105. 'description': video_description,
  106. 'uploader': video_uploader,
  107. 'age_limit': age_limit,
  108. }
  109. sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw)
  110. sources = json.loads(sources_json)
  111. formats = [{
  112. 'format_id': '%s' % i,
  113. 'format_note': s.get('label'),
  114. 'url': s['file'],
  115. } for i, s in enumerate(sources)]
  116. for i, s in enumerate(sources):
  117. # Removing '.h264_*.mp4' gives the raw video, which is essentially
  118. # the same video without the LiveLeak logo at the top (see
  119. # https://github.com/rg3/youtube-dl/pull/4768)
  120. orig_url = re.sub(r'\.h264_.+?\.mp4', '', s['file'])
  121. if s['file'] != orig_url:
  122. formats.append({
  123. 'format_id': 'original-%s' % i,
  124. 'format_note': s.get('label'),
  125. 'url': orig_url,
  126. 'preference': 1,
  127. })
  128. self._sort_formats(formats)
  129. return {
  130. 'id': video_id,
  131. 'title': video_title,
  132. 'description': video_description,
  133. 'uploader': video_uploader,
  134. 'formats': formats,
  135. 'age_limit': age_limit,
  136. 'thumbnail': video_thumbnail,
  137. }