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.

53 lines
1.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. HEADRequest,
  7. ExtractorError,
  8. int_or_none,
  9. )
  10. class TFOIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?tfo\.org/(?:en|fr)/(?:[^/]+/){2}(?P<id>\d+)'
  12. _TEST = {
  13. 'url': 'http://www.tfo.org/en/universe/tfo-247/100463871/video-game-hackathon',
  14. 'md5': '47c987d0515561114cf03d1226a9d4c7',
  15. 'info_dict': {
  16. 'id': '100463871',
  17. 'ext': 'mp4',
  18. 'title': 'Video Game Hackathon',
  19. 'description': 'md5:558afeba217c6c8d96c60e5421795c07',
  20. 'upload_date': '20160212',
  21. 'timestamp': 1455310233,
  22. }
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. self._request_webpage(HEADRequest('http://www.tfo.org/'), video_id)
  27. infos = self._download_json(
  28. 'http://www.tfo.org/api/web/video/get_infos', video_id, data=json.dumps({
  29. 'product_id': video_id,
  30. }).encode(), headers={
  31. 'X-tfo-session': self._get_cookies('http://www.tfo.org/')['tfo-session'].value,
  32. })
  33. if infos.get('success') == 0:
  34. raise ExtractorError('%s said: %s' % (self.IE_NAME, infos['msg']), expected=True)
  35. video_data = infos['data']
  36. return {
  37. '_type': 'url_transparent',
  38. 'id': video_id,
  39. 'url': 'limelight:media:' + video_data['llid'],
  40. 'title': video_data['title'],
  41. 'description': video_data.get('description'),
  42. 'series': video_data.get('collection'),
  43. 'season_number': int_or_none(video_data.get('season')),
  44. 'episode_number': int_or_none(video_data.get('episode')),
  45. 'duration': int_or_none(video_data.get('duration')),
  46. 'ie_key': 'LimelightMedia',
  47. }