]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/jwplatform.py
[extractor/JWPlatform] Fix extractor (#5112)
[yt-dlp.git] / yt_dlp / extractor / jwplatform.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import unsmuggle_url
5
6
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': 'fa8899fa601eb7c83a64e9d568bdf325',
12 'info_dict': {
13 'id': 'nPripu9l',
14 'ext': 'mov',
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 }
20 }, {
21 'url': 'https://cdn.jwplayer.com/players/nPripu9l-ALJ3XQCI.js',
22 'only_matching': True,
23 }]
24
25 _WEBPAGE_TESTS = [{
26 # JWPlatform iframe
27 'url': 'https://www.covermagazine.co.uk/feature/2465255/business-protection-involved',
28 'info_dict': {
29 'id': 'AG26UQXM',
30 'ext': 'mp4',
31 'upload_date': '20160719',
32 'timestamp': 1468923808,
33 'title': '2016_05_18 Cover L&G Business Protection V1 FINAL.mp4',
34 'thumbnail': 'https://cdn.jwplayer.com/v2/media/AG26UQXM/poster.jpg?width=720',
35 'description': '',
36 'duration': 294.0,
37 },
38 }, {
39 # Player url not surrounded by quotes
40 'url': 'https://www.deutsche-kinemathek.de/en/online/streaming/darling-berlin',
41 'info_dict': {
42 'id': 'R10NQdhY',
43 'title': 'Playgirl',
44 'ext': 'mp4',
45 'upload_date': '20220624',
46 'thumbnail': 'https://cdn.jwplayer.com/v2/media/R10NQdhY/poster.jpg?width=720',
47 'timestamp': 1656064800,
48 'description': 'BRD 1966, Will Tremper',
49 'duration': 5146.0,
50 },
51 'params': {'allowed_extractors': ['generic', 'jwplatform']},
52 }]
53
54 @classmethod
55 def _extract_embed_urls(cls, url, webpage):
56 for tag, key in ((r'(?:script|iframe)', 'src'), ('input', 'value')):
57 # <input value=URL> is used by hyland.com
58 # if we find <iframe>, dont look for <input>
59 ret = re.findall(
60 r'<%s[^>]+?%s=["\']?((?:https?:)?//(?:content\.jwplatform|cdn\.jwplayer)\.com/players/[a-zA-Z0-9]{8})' % (tag, key),
61 webpage)
62 if ret:
63 return ret
64 mobj = re.search(r'<div\b[^>]* data-video-jw-id="([a-zA-Z0-9]{8})"', webpage)
65 if mobj:
66 return [f'jwplatform:{mobj.group(1)}']
67
68 def _real_extract(self, url):
69 url, smuggled_data = unsmuggle_url(url, {})
70 self._initialize_geo_bypass({
71 'countries': smuggled_data.get('geo_countries'),
72 })
73 video_id = self._match_id(url)
74 json_data = self._download_json('https://cdn.jwplayer.com/v2/media/' + video_id, video_id)
75 return self._parse_jwplayer_data(json_data, video_id)