tfo.py 1.9 KB

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