]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tfo.py
[extractor/generic] Use `Accept-Encoding: identity` for initial request
[yt-dlp.git] / yt_dlp / extractor / tfo.py
1 import json
2
3 from .common import InfoExtractor
4 from ..utils import (
5 HEADRequest,
6 ExtractorError,
7 int_or_none,
8 clean_html,
9 )
10
11
12 class TFOIE(InfoExtractor):
13 _GEO_COUNTRIES = ['CA']
14 _VALID_URL = r'https?://(?:www\.)?tfo\.org/(?:en|fr)/(?:[^/]+/){2}(?P<id>\d+)'
15 _TEST = {
16 'url': 'http://www.tfo.org/en/universe/tfo-247/100463871/video-game-hackathon',
17 'md5': 'cafbe4f47a8dae0ca0159937878100d6',
18 'info_dict': {
19 'id': '7da3d50e495c406b8fc0b997659cc075',
20 'ext': 'mp4',
21 'title': 'Video Game Hackathon',
22 'description': 'md5:558afeba217c6c8d96c60e5421795c07',
23 }
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
41 return {
42 '_type': 'url_transparent',
43 'id': video_id,
44 'url': 'limelight:media:' + video_data['llid'],
45 'title': video_data['title'],
46 'description': video_data.get('description'),
47 'series': video_data.get('collection'),
48 'season_number': int_or_none(video_data.get('season')),
49 'episode_number': int_or_none(video_data.get('episode')),
50 'duration': int_or_none(video_data.get('duration')),
51 'ie_key': 'LimelightMedia',
52 }