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.

98 lines
3.8 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'^(?:http://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)'
  8. _TESTS = [{
  9. 'url': 'http://www.liveleak.com/view?i=757_1364311680',
  10. 'md5': '0813c2430bea7a46bf13acf3406992f4',
  11. 'info_dict': {
  12. 'id': '757_1364311680',
  13. 'ext': 'mp4',
  14. 'description': 'extremely bad day for this guy..!',
  15. 'uploader': 'ljfriel2',
  16. 'title': 'Most unlucky car accident'
  17. }
  18. },
  19. {
  20. 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
  21. 'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf',
  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. }
  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. def _real_extract(self, url):
  43. mobj = re.match(self._VALID_URL, url)
  44. video_id = mobj.group('video_id')
  45. webpage = self._download_webpage(url, video_id)
  46. video_title = self._og_search_title(webpage).replace('LiveLeak.com -', '').strip()
  47. video_description = self._og_search_description(webpage)
  48. video_uploader = self._html_search_regex(
  49. r'By:.*?(\w+)</a>', webpage, 'uploader', fatal=False)
  50. age_limit = int_or_none(self._search_regex(
  51. r'you confirm that you are ([0-9]+) years and over.',
  52. webpage, 'age limit', default=None))
  53. sources_raw = self._search_regex(
  54. r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None)
  55. if sources_raw is None:
  56. alt_source = self._search_regex(
  57. r'(file: ".*?"),', webpage, 'video URL', default=None)
  58. if alt_source:
  59. sources_raw = '[{ %s}]' % alt_source
  60. else:
  61. # Maybe an embed?
  62. embed_url = self._search_regex(
  63. r'<iframe[^>]+src="(http://www.prochan.com/embed\?[^"]+)"',
  64. webpage, 'embed URL')
  65. return {
  66. '_type': 'url_transparent',
  67. 'url': embed_url,
  68. 'id': video_id,
  69. 'title': video_title,
  70. 'description': video_description,
  71. 'uploader': video_uploader,
  72. 'age_limit': age_limit,
  73. }
  74. sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw)
  75. sources = json.loads(sources_json)
  76. formats = [{
  77. 'format_note': s.get('label'),
  78. 'url': s['file'],
  79. } for s in sources]
  80. self._sort_formats(formats)
  81. return {
  82. 'id': video_id,
  83. 'title': video_title,
  84. 'description': video_description,
  85. 'uploader': video_uploader,
  86. 'formats': formats,
  87. 'age_limit': age_limit,
  88. }