]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/jwplatform.py
[extractors] Use new framework for existing embeds (#4307)
[yt-dlp.git] / yt_dlp / extractor / jwplatform.py
CommitLineData
7cb09524 1import re
2
77302fe5 3from .common import InfoExtractor
b7788822 4from ..utils import unsmuggle_url
77302fe5 5
6
a4a554a7 7class JWPlatformIE(InfoExtractor):
f3c0c773 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})'
7c072f00 9 _TESTS = [{
d1e440a4
YCH
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 }
7c072f00
RA
20 }, {
21 'url': 'https://cdn.jwplayer.com/players/nPripu9l-ALJ3XQCI.js',
22 'only_matching': True,
23 }]
d1e440a4 24
bfd973ec 25 @classmethod
26 def _extract_embed_urls(cls, url, webpage):
389e2956 27 for tag, key in ((r'(?:script|iframe)', 'src'), ('input', 'value')):
28 # <input value=URL> is used by hyland.com
29 # if we find <iframe>, dont look for <input>
30 ret = re.findall(
31 r'<%s[^>]+?%s=["\']((?:https?:)?//(?:content\.jwplatform|cdn\.jwplayer)\.com/players/[a-zA-Z0-9]{8})' % (tag, key),
32 webpage)
33 if ret:
34 return ret
55baa67c 35 mobj = re.search(r'<div\b[^>]* data-video-jw-id="([a-zA-Z0-9]{8})"', webpage)
36 if mobj:
37 return [f'jwplatform:{mobj.group(1)}']
d1e440a4
YCH
38
39 def _real_extract(self, url):
b7788822
S
40 url, smuggled_data = unsmuggle_url(url, {})
41 self._initialize_geo_bypass({
42 'countries': smuggled_data.get('geo_countries'),
43 })
d1e440a4 44 video_id = self._match_id(url)
7c072f00 45 json_data = self._download_json('https://cdn.jwplayer.com/v2/media/' + video_id, video_id)
d1e440a4 46 return self._parse_jwplayer_data(json_data, video_id)