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.

75 lines
2.8 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. dict_get,
  5. float_or_none,
  6. int_or_none,
  7. unified_timestamp,
  8. update_url_query,
  9. url_or_none,
  10. )
  11. class TruNewsIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?trunews\.com/stream/(?P<id>[^/?#&]+)'
  13. _TEST = {
  14. 'url': 'https://www.trunews.com/stream/will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
  15. 'md5': 'a19c024c3906ff954fac9b96ce66bb08',
  16. 'info_dict': {
  17. 'id': '5c5a21e65d3c196e1c0020cc',
  18. 'display_id': 'will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
  19. 'ext': 'mp4',
  20. 'title': "Will Democrats Stage a Circus During President Trump's State of the Union Speech?",
  21. 'description': 'md5:c583b72147cc92cf21f56a31aff7a670',
  22. 'duration': 3685,
  23. 'timestamp': 1549411440,
  24. 'upload_date': '20190206',
  25. },
  26. 'add_ie': ['Zype'],
  27. }
  28. def _real_extract(self, url):
  29. display_id = self._match_id(url)
  30. video = self._download_json(
  31. 'https://api.zype.com/videos', display_id, query={
  32. 'app_key': 'PUVKp9WgGUb3-JUw6EqafLx8tFVP6VKZTWbUOR-HOm__g4fNDt1bCsm_LgYf_k9H',
  33. 'per_page': 1,
  34. 'active': 'true',
  35. 'friendly_title': display_id,
  36. })['response'][0]
  37. zype_id = video['_id']
  38. thumbnails = []
  39. thumbnails_list = video.get('thumbnails')
  40. if isinstance(thumbnails_list, list):
  41. for thumbnail in thumbnails_list:
  42. if not isinstance(thumbnail, dict):
  43. continue
  44. thumbnail_url = url_or_none(thumbnail.get('url'))
  45. if not thumbnail_url:
  46. continue
  47. thumbnails.append({
  48. 'url': thumbnail_url,
  49. 'width': int_or_none(thumbnail.get('width')),
  50. 'height': int_or_none(thumbnail.get('height')),
  51. })
  52. return {
  53. '_type': 'url_transparent',
  54. 'url': update_url_query(
  55. 'https://player.zype.com/embed/%s.js' % zype_id,
  56. {'api_key': 'X5XnahkjCwJrT_l5zUqypnaLEObotyvtUKJWWlONxDoHVjP8vqxlArLV8llxMbyt'}),
  57. 'ie_key': 'Zype',
  58. 'id': zype_id,
  59. 'display_id': display_id,
  60. 'title': video.get('title'),
  61. 'description': dict_get(video, ('description', 'ott_description', 'short_description')),
  62. 'duration': int_or_none(video.get('duration')),
  63. 'timestamp': unified_timestamp(video.get('published_at')),
  64. 'average_rating': float_or_none(video.get('rating')),
  65. 'view_count': int_or_none(video.get('request_count')),
  66. 'thumbnails': thumbnails,
  67. }