[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / jwplatform.py
blob7d5a931b5f8224674a44c6674281e9492eb5679c
1 import re
3 from .common import InfoExtractor
4 from ..utils import unsmuggle_url
7 class JWPlatformIE(InfoExtractor):
8 _VALID_URL = r'(?:https?://(?:content\.jwplatform|cdn\.jwplayer)\.com/(?:(?:feed|player|thumb|preview|manifest)s|jw6|v2/media)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
9 _TESTS = [{
10 'url': 'http://content.jwplatform.com/players/nPripu9l-ALJ3XQCI.js',
11 'md5': '3aa16e4f6860e6e78b7df5829519aed3',
12 'info_dict': {
13 'id': 'nPripu9l',
14 'ext': 'mp4',
15 'title': 'Big Buck Bunny Trailer',
16 'description': 'Big Buck Bunny is a short animated film by the Blender Institute. It is made using free and open source software.',
17 'upload_date': '20081127',
18 'timestamp': 1227796140,
19 'duration': 32.0,
20 'thumbnail': 'https://cdn.jwplayer.com/v2/media/nPripu9l/poster.jpg?width=720',
22 }, {
23 'url': 'https://cdn.jwplayer.com/players/nPripu9l-ALJ3XQCI.js',
24 'only_matching': True,
27 _WEBPAGE_TESTS = [{
28 # JWPlatform iframe
29 'url': 'https://www.covermagazine.co.uk/feature/2465255/business-protection-involved',
30 'info_dict': {
31 'id': 'AG26UQXM',
32 'ext': 'mp4',
33 'upload_date': '20160719',
34 'timestamp': 1468923808,
35 'title': '2016_05_18 Cover L&G Business Protection V1 FINAL.mp4',
36 'thumbnail': 'https://cdn.jwplayer.com/v2/media/AG26UQXM/poster.jpg?width=720',
37 'description': '',
38 'duration': 294.0,
40 }, {
41 # Player url not surrounded by quotes
42 'url': 'https://www.deutsche-kinemathek.de/en/online/streaming/school-trip',
43 'info_dict': {
44 'id': 'jUxh5uin',
45 'title': 'Klassenfahrt',
46 'ext': 'mp4',
47 'upload_date': '20230109',
48 'thumbnail': 'https://cdn.jwplayer.com/v2/media/jUxh5uin/poster.jpg?width=720',
49 'timestamp': 1673270298,
50 'description': '',
51 'duration': 5193.0,
53 'params': {'allowed_extractors': ['generic', 'jwplatform']},
54 }, {
55 # iframe src attribute includes backslash before URL string
56 'url': 'https://www.elespectador.com/colombia/video-asi-se-evito-la-fuga-de-john-poulos-presunto-feminicida-de-valentina-trespalacios-explicacion',
57 'info_dict': {
58 'id': 'QD3gsexj',
59 'title': 'Así se evitó la fuga de John Poulos, presunto feminicida de Valentina Trespalacios',
60 'ext': 'mp4',
61 'upload_date': '20230127',
62 'thumbnail': 'https://cdn.jwplayer.com/v2/media/QD3gsexj/poster.jpg?width=720',
63 'timestamp': 1674862986,
64 'description': 'md5:128fd74591c4e1fc2da598c5cb6f5ce4',
65 'duration': 263.0,
69 @classmethod
70 def _extract_embed_urls(cls, url, webpage):
71 for tag, key in ((r'(?:script|iframe)', 'src'), ('input', 'value')):
72 # <input value=URL> is used by hyland.com
73 # if we find <iframe>, dont look for <input>
74 ret = re.findall(
75 rf'<{tag}[^>]+?{key}=\\?["\']?((?:https?:)?//(?:content\.jwplatform|cdn\.jwplayer)\.com/players/[a-zA-Z0-9]{{8}})',
76 webpage)
77 if ret:
78 return ret
79 mobj = re.search(r'<div\b[^>]* data-video-jw-id="([a-zA-Z0-9]{8})"', webpage)
80 if mobj:
81 return [f'jwplatform:{mobj.group(1)}']
83 def _real_extract(self, url):
84 url, smuggled_data = unsmuggle_url(url, {})
85 self._initialize_geo_bypass({
86 'countries': smuggled_data.get('geo_countries'),
88 video_id = self._match_id(url)
89 json_data = self._download_json('https://cdn.jwplayer.com/v2/media/' + video_id, video_id)
90 return self._parse_jwplayer_data(json_data, video_id)