]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fox.py
Start new release.
[youtubedl] / youtube_dl / extractor / fox.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 # import json
5 # import uuid
6
7 from .adobepass import AdobePassIE
8 from ..utils import (
9 int_or_none,
10 parse_age_limit,
11 parse_duration,
12 try_get,
13 unified_timestamp,
14 update_url_query,
15 )
16
17
18 class FOXIE(AdobePassIE):
19 _VALID_URL = r'https?://(?:www\.)?(?:fox\.com|nationalgeographic\.com/tv)/watch/(?P<id>[\da-fA-F]+)'
20 _TESTS = [{
21 # clip
22 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
23 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
24 'info_dict': {
25 'id': '4b765a60490325103ea69888fb2bd4e8',
26 'ext': 'mp4',
27 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
28 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
29 'duration': 102,
30 'timestamp': 1504291893,
31 'upload_date': '20170901',
32 'creator': 'FOX',
33 'series': 'Gotham',
34 },
35 'params': {
36 'skip_download': True,
37 },
38 }, {
39 # episode, geo-restricted
40 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
41 'only_matching': True,
42 }, {
43 # episode, geo-restricted, tv provided required
44 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
45 'only_matching': True,
46 }, {
47 'url': 'https://www.nationalgeographic.com/tv/watch/f690e05ebbe23ab79747becd0cc223d1/',
48 'only_matching': True,
49 }]
50 # _access_token = None
51
52 # def _call_api(self, path, video_id, data=None):
53 # headers = {
54 # 'X-Api-Key': '238bb0a0c2aba67922c48709ce0c06fd',
55 # }
56 # if self._access_token:
57 # headers['Authorization'] = 'Bearer ' + self._access_token
58 # return self._download_json(
59 # 'https://api2.fox.com/v2.0/' + path, video_id, data=data, headers=headers)
60
61 # def _real_initialize(self):
62 # self._access_token = self._call_api(
63 # 'login', None, json.dumps({
64 # 'deviceId': compat_str(uuid.uuid4()),
65 # }).encode())['accessToken']
66
67 def _real_extract(self, url):
68 video_id = self._match_id(url)
69
70 video = self._download_json(
71 'https://api.fox.com/fbc-content/v1_5/video/%s' % video_id,
72 video_id, headers={
73 'apikey': 'abdcbed02c124d393b39e818a4312055',
74 'Content-Type': 'application/json',
75 'Referer': url,
76 })
77 # video = self._call_api('vodplayer/' + video_id, video_id)
78
79 title = video['name']
80 release_url = video['videoRelease']['url']
81 # release_url = video['url']
82
83 data = try_get(
84 video, lambda x: x['trackingData']['properties'], dict) or {}
85
86 rating = video.get('contentRating')
87 if data.get('authRequired'):
88 resource = self._get_mvpd_resource(
89 'fbc-fox', title, video.get('guid'), rating)
90 release_url = update_url_query(
91 release_url, {
92 'auth': self._extract_mvpd_auth(
93 url, video_id, 'fbc-fox', resource)
94 })
95 m3u8_url = self._download_json(release_url, video_id)['playURL']
96 formats = self._extract_m3u8_formats(
97 m3u8_url, video_id, 'mp4',
98 entry_protocol='m3u8_native', m3u8_id='hls')
99 self._sort_formats(formats)
100
101 duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
102 video.get('duration')) or parse_duration(video.get('duration'))
103 timestamp = unified_timestamp(video.get('datePublished'))
104 creator = data.get('brand') or data.get('network') or video.get('network')
105 series = video.get('seriesName') or data.get(
106 'seriesName') or data.get('show')
107
108 subtitles = {}
109 for doc_rel in video.get('documentReleases', []):
110 rel_url = doc_rel.get('url')
111 if not url or doc_rel.get('format') != 'SCC':
112 continue
113 subtitles['en'] = [{
114 'url': rel_url,
115 'ext': 'scc',
116 }]
117 break
118
119 return {
120 'id': video_id,
121 'title': title,
122 'formats': formats,
123 'description': video.get('description'),
124 'duration': duration,
125 'timestamp': timestamp,
126 'age_limit': parse_age_limit(rating),
127 'creator': creator,
128 'series': series,
129 'season_number': int_or_none(video.get('seasonNumber')),
130 'episode': video.get('name'),
131 'episode_number': int_or_none(video.get('episodeNumber')),
132 'release_year': int_or_none(video.get('releaseYear')),
133 'subtitles': subtitles,
134 }