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