]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sky.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / sky.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 extract_attributes,
6 strip_or_none,
7 )
8
9
10 class SkyBaseIE(InfoExtractor):
11 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
12 _SDC_EL_REGEX = r'(?s)(<div[^>]+data-(?:component-name|fn)="sdc-(?:articl|sit)e-video"[^>]*>)'
13
14 def _process_video_element(self, webpage, sdc_el, url):
15 sdc = extract_attributes(sdc_el)
16 provider = sdc.get('data-provider')
17 if provider == 'brightcove':
18 video_id = sdc['data-video-id']
19 account_id = sdc.get('data-account-id') or '6058004172001'
20 player_id = sdc.get('data-player-id') or 'RC9PQUaJ6'
21 video_url = self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id)
22 ie_key = 'BrightcoveNew'
23
24 return {
25 '_type': 'url_transparent',
26 'id': video_id,
27 'url': video_url,
28 'ie_key': ie_key,
29 }
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 webpage = self._download_webpage(url, video_id)
34 info = self._process_video_element(webpage, self._search_regex(
35 self._SDC_EL_REGEX, webpage, 'sdc element'), url)
36 info.update({
37 'title': self._og_search_title(webpage),
38 'description': strip_or_none(self._og_search_description(webpage)),
39 })
40 return info
41
42
43 class SkySportsIE(SkyBaseIE):
44 IE_NAME = 'sky:sports'
45 _VALID_URL = r'https?://(?:www\.)?skysports\.com/watch/video/([^/]+/)*(?P<id>[0-9]+)'
46 _TESTS = [{
47 'url': 'http://www.skysports.com/watch/video/10328419/bale-its-our-time-to-shine',
48 'md5': '77d59166cddc8d3cb7b13e35eaf0f5ec',
49 'info_dict': {
50 'id': 'o3eWJnNDE6l7kfNO8BOoBlRxXRQ4ANNQ',
51 'ext': 'mp4',
52 'title': 'Bale: It\'s our time to shine',
53 'description': 'md5:e88bda94ae15f7720c5cb467e777bb6d',
54 },
55 'add_ie': ['BrightcoveNew'],
56 }, {
57 'url': 'https://www.skysports.com/watch/video/sports/f1/12160544/abu-dhabi-gp-the-notebook',
58 'only_matching': True,
59 }, {
60 'url': 'https://www.skysports.com/watch/video/tv-shows/12118508/rainford-brent-how-ace-programme-helps',
61 'only_matching': True,
62 }]
63
64
65 class SkyNewsIE(SkyBaseIE):
66 IE_NAME = 'sky:news'
67 _VALID_URL = r'https?://news\.sky\.com/video/[0-9a-z-]+-(?P<id>[0-9]+)'
68 _TEST = {
69 'url': 'https://news.sky.com/video/russian-plane-inspected-after-deadly-fire-11712962',
70 'md5': '411e8893fd216c75eaf7e4c65d364115',
71 'info_dict': {
72 'id': 'ref:1ua21xaDE6lCtZDmbYfl8kwsKLooJbNM',
73 'ext': 'mp4',
74 'title': 'Russian plane inspected after deadly fire',
75 'description': 'The Russian Investigative Committee has released video of the wreckage of a passenger plane which caught fire near Moscow.',
76 'uploader_id': '6058004172001',
77 'timestamp': 1567112345,
78 'upload_date': '20190829',
79 },
80 'add_ie': ['BrightcoveNew'],
81 }
82
83
84 class SkyNewsStoryIE(SkyBaseIE):
85 IE_NAME = 'sky:news:story'
86 _VALID_URL = r'https?://news\.sky\.com/story/[0-9a-z-]+-(?P<id>[0-9]+)'
87 _TEST = {
88 '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',
89 'info_dict': {
90 'id': 'ref:0714acb9-123d-42c8-91b8-5c1bc6c73f20',
91 'title': 'md5:e408dd7aad63f31a1817bbe40c7d276f',
92 'description': 'md5:a881e12f49212f92be2befe4a09d288a',
93 'ext': 'mp4',
94 'upload_date': '20211027',
95 'timestamp': 1635317494,
96 'uploader_id': '6058004172001',
97 },
98 }
99
100 def _real_extract(self, url):
101 article_id = self._match_id(url)
102 webpage = self._download_webpage(url, article_id)
103
104 entries = [self._process_video_element(webpage, sdc_el, url)
105 for sdc_el in re.findall(self._SDC_EL_REGEX, webpage)]
106
107 return self.playlist_result(
108 entries, article_id, self._og_search_title(webpage),
109 self._html_search_meta(['og:description', 'description'], webpage))
110
111
112 class SkySportsNewsIE(SkyBaseIE):
113 IE_NAME = 'sky:sports:news'
114 _VALID_URL = r'https?://(?:www\.)?skysports\.com/([^/]+/)*news/\d+/(?P<id>\d+)'
115 _TEST = {
116 'url': 'http://www.skysports.com/golf/news/12176/10871916/dustin-johnson-ready-to-conquer-players-championship-at-tpc-sawgrass',
117 'info_dict': {
118 'id': '10871916',
119 'title': 'Dustin Johnson ready to conquer Players Championship at TPC Sawgrass',
120 'description': 'Dustin Johnson is confident he can continue his dominant form in 2017 by adding the Players Championship to his list of victories.',
121 },
122 'playlist_count': 2,
123 }
124
125 def _real_extract(self, url):
126 article_id = self._match_id(url)
127 webpage = self._download_webpage(url, article_id)
128
129 entries = []
130 for sdc_el in re.findall(self._SDC_EL_REGEX, webpage):
131 entries.append(self._process_video_element(webpage, sdc_el, url))
132
133 return self.playlist_result(
134 entries, article_id, self._og_search_title(webpage),
135 self._html_search_meta(['og:description', 'description'], webpage))