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.

52 lines
1.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. smuggle_url,
  7. )
  8. class TVAIE(InfoExtractor):
  9. _VALID_URL = r'https?://videos\.tva\.ca/details/_(?P<id>\d+)'
  10. _TEST = {
  11. 'url': 'https://videos.tva.ca/details/_5596811470001',
  12. 'info_dict': {
  13. 'id': '5596811470001',
  14. 'ext': 'mp4',
  15. 'title': 'Un extrait de l\'épisode du dimanche 8 octobre 2017 !',
  16. 'uploader_id': '5481942443001',
  17. 'upload_date': '20171003',
  18. 'timestamp': 1507064617,
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. }
  24. }
  25. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5481942443001/default_default/index.html?videoId=%s'
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. video_data = self._download_json(
  29. 'https://videos.tva.ca/proxy/item/_' + video_id, video_id, headers={
  30. 'Accept': 'application/json',
  31. })
  32. def get_attribute(key):
  33. for attribute in video_data.get('attributes', []):
  34. if attribute.get('key') == key:
  35. return attribute.get('value')
  36. return None
  37. return {
  38. '_type': 'url_transparent',
  39. 'id': video_id,
  40. 'title': get_attribute('title'),
  41. 'url': smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % video_id, {'geo_countries': ['CA']}),
  42. 'description': get_attribute('description'),
  43. 'thumbnail': get_attribute('image-background') or get_attribute('image-landscape'),
  44. 'duration': float_or_none(get_attribute('video-duration'), 1000),
  45. 'ie_key': 'BrightcoveNew',
  46. }