]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fox.py
New upstream version 2017.09.24
[youtubedl] / youtube_dl / extractor / fox.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .adobepass import AdobePassIE
5 from ..utils import (
6 int_or_none,
7 parse_age_limit,
8 parse_duration,
9 try_get,
10 unified_timestamp,
11 )
12
13
14 class FOXIE(AdobePassIE):
15 _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
16 _TESTS = [{
17 # clip
18 'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
19 'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
20 'info_dict': {
21 'id': '4b765a60490325103ea69888fb2bd4e8',
22 'ext': 'mp4',
23 'title': 'Aftermath: Bruce Wayne Develops Into The Dark Knight',
24 'description': 'md5:549cd9c70d413adb32ce2a779b53b486',
25 'duration': 102,
26 'timestamp': 1504291893,
27 'upload_date': '20170901',
28 'creator': 'FOX',
29 'series': 'Gotham',
30 },
31 'params': {
32 'skip_download': True,
33 },
34 }, {
35 # episode, geo-restricted
36 'url': 'https://www.fox.com/watch/087036ca7f33c8eb79b08152b4dd75c1/',
37 'only_matching': True,
38 }, {
39 # episode, geo-restricted, tv provided required
40 'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
41 'only_matching': True,
42 }]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46
47 video = self._download_json(
48 'https://api.fox.com/fbc-content/v1_4/video/%s' % video_id,
49 video_id, headers={
50 'apikey': 'abdcbed02c124d393b39e818a4312055',
51 'Content-Type': 'application/json',
52 'Referer': url,
53 })
54
55 title = video['name']
56
57 m3u8_url = self._download_json(
58 video['videoRelease']['url'], video_id)['playURL']
59
60 formats = self._extract_m3u8_formats(
61 m3u8_url, video_id, 'mp4',
62 entry_protocol='m3u8_native', m3u8_id='hls')
63 self._sort_formats(formats)
64
65 description = video.get('description')
66 duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
67 video.get('duration')) or parse_duration(video.get('duration'))
68 timestamp = unified_timestamp(video.get('datePublished'))
69 age_limit = parse_age_limit(video.get('contentRating'))
70
71 data = try_get(
72 video, lambda x: x['trackingData']['properties'], dict) or {}
73
74 creator = data.get('brand') or data.get('network') or video.get('network')
75
76 series = video.get('seriesName') or data.get(
77 'seriesName') or data.get('show')
78 season_number = int_or_none(video.get('seasonNumber'))
79 episode = video.get('name')
80 episode_number = int_or_none(video.get('episodeNumber'))
81 release_year = int_or_none(video.get('releaseYear'))
82
83 if data.get('authRequired'):
84 # TODO: AP
85 pass
86
87 return {
88 'id': video_id,
89 'title': title,
90 'description': description,
91 'duration': duration,
92 'timestamp': timestamp,
93 'age_limit': age_limit,
94 'creator': creator,
95 'series': series,
96 'season_number': season_number,
97 'episode': episode,
98 'episode_number': episode_number,
99 'release_year': release_year,
100 'formats': formats,
101 }