logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

crooksandliars.py (2061B)


  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. qualities,
  6. )
  7. class CrooksAndLiarsIE(InfoExtractor):
  8. _VALID_URL = r'https?://embed\.crooksandliars\.com/(?:embed|v)/(?P<id>[A-Za-z0-9]+)'
  9. _TESTS = [{
  10. 'url': 'https://embed.crooksandliars.com/embed/8RUoRhRi',
  11. 'info_dict': {
  12. 'id': '8RUoRhRi',
  13. 'ext': 'mp4',
  14. 'title': 'Fox & Friends Says Protecting Atheists From Discrimination Is Anti-Christian!',
  15. 'description': 'md5:e1a46ad1650e3a5ec7196d432799127f',
  16. 'thumbnail': r're:^https?://.*\.jpg',
  17. 'timestamp': 1428207000,
  18. 'upload_date': '20150405',
  19. 'uploader': 'Heather',
  20. 'duration': 236,
  21. }
  22. }, {
  23. 'url': 'http://embed.crooksandliars.com/v/MTE3MjUtMzQ2MzA',
  24. 'only_matching': True,
  25. }]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(
  29. 'http://embed.crooksandliars.com/embed/%s' % video_id, video_id)
  30. manifest = self._parse_json(
  31. self._search_regex(
  32. r'var\s+manifest\s*=\s*({.+?})\n', webpage, 'manifest JSON'),
  33. video_id)
  34. quality = qualities(('webm_low', 'mp4_low', 'webm_high', 'mp4_high'))
  35. formats = [{
  36. 'url': item['url'],
  37. 'format_id': item['type'],
  38. 'quality': quality(item['type']),
  39. } for item in manifest['flavors'] if item['mime'].startswith('video/')]
  40. self._sort_formats(formats)
  41. return {
  42. 'url': url,
  43. 'id': video_id,
  44. 'title': manifest['title'],
  45. 'description': manifest.get('description'),
  46. 'thumbnail': self._proto_relative_url(manifest.get('poster')),
  47. 'timestamp': int_or_none(manifest.get('created')),
  48. 'uploader': manifest.get('author'),
  49. 'duration': int_or_none(manifest.get('duration')),
  50. 'formats': formats,
  51. }