]>
Commit | Line | Data |
---|---|---|
df43389a RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
29f7c58a | 4 | import re |
5 | ||
df43389a | 6 | from .common import InfoExtractor |
44cca168 RA |
7 | from ..utils import ( |
8 | extract_attributes, | |
9 | smuggle_url, | |
10 | strip_or_none, | |
11 | urljoin, | |
12 | ) | |
df43389a RA |
13 | |
14 | ||
71ebd35d | 15 | class SkyBaseIE(InfoExtractor): |
29f7c58a | 16 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s' |
17 | _SDC_EL_REGEX = r'(?s)(<div[^>]+data-(?:component-name|fn)="sdc-(?:articl|sit)e-video"[^>]*>)' | |
18 | ||
19 | def _process_ooyala_element(self, webpage, sdc_el, url): | |
20 | sdc = extract_attributes(sdc_el) | |
21 | provider = sdc.get('data-provider') | |
22 | if provider == 'ooyala': | |
23 | video_id = sdc['data-sdc-video-id'] | |
24 | video_url = 'ooyala:%s' % video_id | |
25 | ie_key = 'Ooyala' | |
26 | ooyala_el = self._search_regex( | |
27 | r'(<div[^>]+class="[^"]*\bsdc-article-video__media-ooyala\b[^"]*"[^>]+data-video-id="%s"[^>]*>)' % video_id, | |
28 | webpage, 'video data', fatal=False) | |
29 | if ooyala_el: | |
30 | ooyala_attrs = extract_attributes(ooyala_el) or {} | |
31 | if ooyala_attrs.get('data-token-required') == 'true': | |
32 | token_fetch_url = (self._parse_json(ooyala_attrs.get( | |
33 | 'data-token-fetch-options', '{}'), | |
34 | video_id, fatal=False) or {}).get('url') | |
35 | if token_fetch_url: | |
36 | embed_token = self._download_json(urljoin( | |
37 | url, token_fetch_url), video_id, fatal=False) | |
38 | if embed_token: | |
39 | video_url = smuggle_url( | |
40 | video_url, {'embed_token': embed_token}) | |
41 | elif provider == 'brightcove': | |
42 | video_id = sdc['data-video-id'] | |
43 | account_id = sdc.get('data-account-id') or '6058004172001' | |
44 | player_id = sdc.get('data-player-id') or 'RC9PQUaJ6' | |
45 | video_url = self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id) | |
46 | ie_key = 'BrightcoveNew' | |
df43389a RA |
47 | |
48 | return { | |
49 | '_type': 'url_transparent', | |
50 | 'id': video_id, | |
44cca168 | 51 | 'url': video_url, |
29f7c58a | 52 | 'ie_key': ie_key, |
53 | } | |
54 | ||
55 | def _real_extract(self, url): | |
56 | video_id = self._match_id(url) | |
57 | webpage = self._download_webpage(url, video_id) | |
58 | info = self._process_ooyala_element(webpage, self._search_regex( | |
59 | self._SDC_EL_REGEX, webpage, 'sdc element'), url) | |
60 | info.update({ | |
df43389a | 61 | 'title': self._og_search_title(webpage), |
a814da3f | 62 | 'description': strip_or_none(self._og_search_description(webpage)), |
29f7c58a | 63 | }) |
64 | return info | |
71ebd35d RA |
65 | |
66 | ||
67 | class SkySportsIE(SkyBaseIE): | |
29f7c58a | 68 | IE_NAME = 'sky:sports' |
69 | _VALID_URL = r'https?://(?:www\.)?skysports\.com/watch/video/([^/]+/)*(?P<id>[0-9]+)' | |
70 | _TESTS = [{ | |
71ebd35d RA |
71 | 'url': 'http://www.skysports.com/watch/video/10328419/bale-its-our-time-to-shine', |
72 | 'md5': '77d59166cddc8d3cb7b13e35eaf0f5ec', | |
73 | 'info_dict': { | |
74 | 'id': 'o3eWJnNDE6l7kfNO8BOoBlRxXRQ4ANNQ', | |
75 | 'ext': 'mp4', | |
76 | 'title': 'Bale: It\'s our time to shine', | |
77 | 'description': 'md5:e88bda94ae15f7720c5cb467e777bb6d', | |
78 | }, | |
79 | 'add_ie': ['Ooyala'], | |
29f7c58a | 80 | }, { |
81 | 'url': 'https://www.skysports.com/watch/video/sports/f1/12160544/abu-dhabi-gp-the-notebook', | |
82 | 'only_matching': True, | |
83 | }, { | |
84 | 'url': 'https://www.skysports.com/watch/video/tv-shows/12118508/rainford-brent-how-ace-programme-helps', | |
85 | 'only_matching': True, | |
86 | }] | |
71ebd35d RA |
87 | |
88 | ||
89 | class SkyNewsIE(SkyBaseIE): | |
29f7c58a | 90 | IE_NAME = 'sky:news' |
71ebd35d RA |
91 | _VALID_URL = r'https?://news\.sky\.com/video/[0-9a-z-]+-(?P<id>[0-9]+)' |
92 | _TEST = { | |
93 | 'url': 'https://news.sky.com/video/russian-plane-inspected-after-deadly-fire-11712962', | |
29f7c58a | 94 | 'md5': '411e8893fd216c75eaf7e4c65d364115', |
71ebd35d | 95 | 'info_dict': { |
29f7c58a | 96 | 'id': 'ref:1ua21xaDE6lCtZDmbYfl8kwsKLooJbNM', |
71ebd35d RA |
97 | 'ext': 'mp4', |
98 | 'title': 'Russian plane inspected after deadly fire', | |
99 | 'description': 'The Russian Investigative Committee has released video of the wreckage of a passenger plane which caught fire near Moscow.', | |
29f7c58a | 100 | 'uploader_id': '6058004172001', |
101 | 'timestamp': 1567112345, | |
102 | 'upload_date': '20190829', | |
71ebd35d | 103 | }, |
29f7c58a | 104 | 'add_ie': ['BrightcoveNew'], |
105 | } | |
106 | ||
107 | ||
b7b186e7 | 108 | class SkyNewsStoryIE(SkyBaseIE): |
109 | IE_NAME = 'sky:news:story' | |
110 | _VALID_URL = r'https?://news\.sky\.com/story/[0-9a-z-]+-(?P<id>[0-9]+)' | |
111 | _TEST = { | |
112 | 'url': 'https://news.sky.com/story/budget-2021-chancellor-rishi-sunak-vows-address-will-deliver-strong-economy-fit-for-a-new-age-of-optimism-12445425', | |
113 | 'info_dict': { | |
114 | 'id': 'ref:0714acb9-123d-42c8-91b8-5c1bc6c73f20', | |
115 | 'title': 'md5:e408dd7aad63f31a1817bbe40c7d276f', | |
116 | 'description': 'md5:a881e12f49212f92be2befe4a09d288a', | |
117 | 'ext': 'mp4', | |
118 | 'upload_date': '20211027', | |
119 | 'timestamp': 1635317494, | |
120 | 'uploader_id': '6058004172001', | |
121 | } | |
122 | } | |
123 | ||
124 | def _real_extract(self, url): | |
125 | article_id = self._match_id(url) | |
126 | webpage = self._download_webpage(url, article_id) | |
127 | ||
128 | entries = [self._process_ooyala_element(webpage, sdc_el, url) | |
129 | for sdc_el in re.findall(self._SDC_EL_REGEX, webpage)] | |
130 | ||
131 | return self.playlist_result( | |
132 | entries, article_id, self._og_search_title(webpage), | |
133 | self._html_search_meta(['og:description', 'description'], webpage)) | |
134 | ||
135 | ||
29f7c58a | 136 | class SkySportsNewsIE(SkyBaseIE): |
137 | IE_NAME = 'sky:sports:news' | |
138 | _VALID_URL = r'https?://(?:www\.)?skysports\.com/([^/]+/)*news/\d+/(?P<id>\d+)' | |
139 | _TEST = { | |
140 | 'url': 'http://www.skysports.com/golf/news/12176/10871916/dustin-johnson-ready-to-conquer-players-championship-at-tpc-sawgrass', | |
141 | 'info_dict': { | |
142 | 'id': '10871916', | |
143 | 'title': 'Dustin Johnson ready to conquer Players Championship at TPC Sawgrass', | |
144 | 'description': 'Dustin Johnson is confident he can continue his dominant form in 2017 by adding the Players Championship to his list of victories.', | |
145 | }, | |
146 | 'playlist_count': 2, | |
71ebd35d | 147 | } |
29f7c58a | 148 | |
149 | def _real_extract(self, url): | |
150 | article_id = self._match_id(url) | |
151 | webpage = self._download_webpage(url, article_id) | |
152 | ||
153 | entries = [] | |
154 | for sdc_el in re.findall(self._SDC_EL_REGEX, webpage): | |
155 | entries.append(self._process_ooyala_element(webpage, sdc_el, url)) | |
156 | ||
157 | return self.playlist_result( | |
158 | entries, article_id, self._og_search_title(webpage), | |
159 | self._html_search_meta(['og:description', 'description'], webpage)) |