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.

63 lines
2.3 KiB

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