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.

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