logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tfo.py (2038B)


  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': 'cafbe4f47a8dae0ca0159937878100d6',
  17. 'info_dict': {
  18. 'id': '7da3d50e495c406b8fc0b997659cc075',
  19. 'ext': 'mp4',
  20. 'title': 'Video Game Hackathon',
  21. 'description': 'md5:558afeba217c6c8d96c60e5421795c07',
  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. if infos.get('code') == 'ErrGeoBlocked':
  35. self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
  36. raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(infos['msg'])), expected=True)
  37. video_data = infos['data']
  38. return {
  39. '_type': 'url_transparent',
  40. 'id': video_id,
  41. 'url': 'limelight:media:' + video_data['llid'],
  42. 'title': video_data['title'],
  43. 'description': video_data.get('description'),
  44. 'series': video_data.get('collection'),
  45. 'season_number': int_or_none(video_data.get('season')),
  46. 'episode_number': int_or_none(video_data.get('episode')),
  47. 'duration': int_or_none(video_data.get('duration')),
  48. 'ie_key': 'LimelightMedia',
  49. }