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.

66 lines
2.3 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. )
  8. class LiveLeakIE(InfoExtractor):
  9. _VALID_URL = r'^(?:http://)?(?:\w+\.)?liveleak\.com/view\?(?:.*?)i=(?P<video_id>[\w_]+)(?:.*)'
  10. _TESTS = [{
  11. 'url': 'http://www.liveleak.com/view?i=757_1364311680',
  12. 'file': '757_1364311680.mp4',
  13. 'md5': '0813c2430bea7a46bf13acf3406992f4',
  14. 'info_dict': {
  15. 'description': 'extremely bad day for this guy..!',
  16. 'uploader': 'ljfriel2',
  17. 'title': 'Most unlucky car accident'
  18. }
  19. },
  20. {
  21. 'url': 'http://www.liveleak.com/view?i=f93_1390833151',
  22. 'file': 'f93_1390833151.mp4',
  23. 'md5': 'd3f1367d14cc3c15bf24fbfbe04b9abf',
  24. 'info_dict': {
  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. def _real_extract(self, url):
  31. mobj = re.match(self._VALID_URL, url)
  32. video_id = mobj.group('video_id')
  33. webpage = self._download_webpage(url, video_id)
  34. sources_raw = self._search_regex(
  35. r'(?s)sources:\s*(\[.*?\]),', webpage, 'video URLs', default=None)
  36. if sources_raw is None:
  37. sources_raw = '[{ %s}]' % (
  38. self._search_regex(r'(file: ".*?"),', webpage, 'video URL'))
  39. sources_json = re.sub(r'\s([a-z]+):\s', r'"\1": ', sources_raw)
  40. sources = json.loads(sources_json)
  41. formats = [{
  42. 'format_note': s.get('label'),
  43. 'url': s['file'],
  44. } for s in sources]
  45. self._sort_formats(formats)
  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. return {
  51. 'id': video_id,
  52. 'title': video_title,
  53. 'description': video_description,
  54. 'uploader': video_uploader,
  55. 'formats': formats,
  56. }