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.

71 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. mimetype2ext,
  6. )
  7. class CrooksAndLiarsIE(InfoExtractor):
  8. _VALID_URL = r'(?:https?:)?//embed.crooksandliars.com/embed/(?P<id>[A-Za-z0-9]+)(?:$|[?#])'
  9. _TESTS = [{
  10. 'url': 'https://embed.crooksandliars.com/embed/8RUoRhRi',
  11. 'info_dict': {
  12. 'id': 'https://embed.crooksandliars.com/embed/8RUoRhRi',
  13. 'title': "Fox & Friends Says Protecting Atheists From Discrimination Is Anti-Christian!",
  14. 'description': "Fox News, Fox & Friends Weekend, April 4, 2015. Read more... http://crooksandliars.com/2015/04/fox-friends-says-protecting-atheists",
  15. 'timestamp': 1428207000,
  16. 'thumbnail': 'https://crooksandliars.com/files/mediaposters/2015/04/31235.jpg?ts=1428207050',
  17. 'uploader': "Heather",
  18. }
  19. }]
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(url, video_id)
  23. manifest = json.loads(self._html_search_regex(r'var manifest = ({.*?})\n', webpage, 'manifest JSON'))
  24. formats = []
  25. for item in manifest['flavors']:
  26. if not item['mime'].startswith('video/'): # XXX: or item['exclude']?
  27. continue
  28. formats.append({
  29. 'format_id': item['type'],
  30. 'ext': mimetype2ext(item['mime']),
  31. 'url': item['url'],
  32. })
  33. # XXX: manifest['url']?
  34. return {
  35. 'url': url,
  36. 'id': video_id,
  37. 'uploader': manifest['author'],
  38. 'title': manifest['title'],
  39. 'description': manifest['description'],
  40. 'thumbnail': self._proto_relative_url(manifest['poster']),
  41. 'duration': manifest['duration'],
  42. 'timestamp': int(manifest['created']),
  43. 'formats': formats,
  44. }
  45. class CrooksAndLiarsArticleIE(InfoExtractor):
  46. _VALID_URL = r'(?:https?:)?//crooksandliars.com/\d+/\d+/(?P<id>[a-z\-]+)(?:/|$)'
  47. _TESTS = [{
  48. 'url': 'http://crooksandliars.com/2015/04/fox-friends-says-protecting-atheists',
  49. 'only_matching': True,
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage(url, video_id)
  54. player_url = self._proto_relative_url(self._html_search_regex(r'<iframe src="(//embed.crooksandliars.com/.*)"', webpage, 'embedded player'))
  55. return {
  56. '_type': 'url',
  57. 'url': player_url
  58. }