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.

127 lines
5.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. }
  18. }, {
  19. 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
  20. 'md5': 'b13a29626183c9d33944e6a04f41aafc',
  21. 'info_dict': {
  22. 'id': 'f93_1390833151',
  23. 'ext': 'mp4',
  24. '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.',
  25. 'uploader': 'ARD_Stinkt',
  26. 'title': 'German Television does first Edward Snowden Interview (ENGLISH)',
  27. }
  28. }, {
  29. 'url': 'http://www.liveleak.com/view?i=4f7_1392687779',
  30. 'md5': '42c6d97d54f1db107958760788c5f48f',
  31. 'info_dict': {
  32. 'id': '4f7_1392687779',
  33. 'ext': 'mp4',
  34. '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.",
  35. 'uploader': 'CapObveus',
  36. 'title': 'Man is Fatally Struck by Reckless Car While Packing up a Moving Truck',
  37. 'age_limit': 18,
  38. }
  39. }, {
  40. # Covers https://github.com/rg3/youtube-dl/pull/5983
  41. 'url': 'http://www.liveleak.com/view?i=801_1409392012',
  42. 'md5': '0b3bec2d888c20728ca2ad3642f0ef15',
  43. 'info_dict': {
  44. 'id': '801_1409392012',
  45. 'ext': 'mp4',
  46. 'description': 'Happened on 27.7.2014. \r\nAt 0:53 you can see people still swimming at near beach.',
  47. 'uploader': 'bony333',
  48. 'title': 'Crazy Hungarian tourist films close call waterspout in Croatia'
  49. }
  50. }]
  51. @staticmethod
  52. def _extract_url(webpage):
  53. mobj = re.search(
  54. r'<iframe[^>]+src="https?://(?:\w+\.)?liveleak\.com/ll_embed\?(?:.*?)i=(?P<id>[\w_]+)(?:.*)',
  55. webpage)
  56. if mobj:
  57. return 'http://www.liveleak.com/view?i=%s' % mobj.group('id')
  58. def _real_extract(self, url):
  59. video_id = self._match_id(url)
  60. webpage = self._download_webpage(url, video_id)
  61. video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip()
  62. video_description = self._og_search_description(webpage)
  63. video_uploader = self._html_search_regex(
  64. r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False)
  65. age_limit = int_or_none(self._search_regex(
  66. r'you confirm that you are ([0-9]+) years and over.',
  67. webpage, 'age limit', default=None))
  68. sources_raw = self._search_regex(
  69. r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None)
  70. if sources_raw is None:
  71. alt_source = self._search_regex(
  72. r'(file: ".*?"),', webpage, 'video URL', default=None)
  73. if alt_source:
  74. sources_raw = '[{ %s}]' % alt_source
  75. else:
  76. # Maybe an embed?
  77. embed_url = self._search_regex(
  78. r'<iframe[^>]+src="(http://www.prochan.com/embed\?[^"]+)"',
  79. webpage, 'embed URL')
  80. return {
  81. '_type': 'url_transparent',
  82. 'url': embed_url,
  83. 'id': video_id,
  84. 'title': video_title,
  85. 'description': video_description,
  86. 'uploader': video_uploader,
  87. 'age_limit': age_limit,
  88. }
  89. sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw)
  90. sources = json.loads(sources_json)
  91. formats = [{
  92. 'format_id': '%s' % i,
  93. 'format_note': s.get('label'),
  94. 'url': s['file'],
  95. } for i, s in enumerate(sources)]
  96. for i, s in enumerate(sources):
  97. # Removing '.h264_*.mp4' gives the raw video, which is essentially
  98. # the same video without the LiveLeak logo at the top (see
  99. # https://github.com/rg3/youtube-dl/pull/4768)
  100. orig_url = re.sub(r'\.h264_.+?\.mp4', '', s['file'])
  101. if s['file'] != orig_url:
  102. formats.append({
  103. 'format_id': 'original-%s' % i,
  104. 'format_note': s.get('label'),
  105. 'url': orig_url,
  106. 'preference': 1,
  107. })
  108. self._sort_formats(formats)
  109. return {
  110. 'id': video_id,
  111. 'title': video_title,
  112. 'description': video_description,
  113. 'uploader': video_uploader,
  114. 'formats': formats,
  115. 'age_limit': age_limit,
  116. }