]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/jwplatform.py
1bf58d517a7404db5b2c2613ab10638f049f6d22
[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)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 @staticmethod
26 def _extract_url(webpage):
27 urls = JWPlatformIE._extract_urls(webpage)
28 return urls[0] if urls else None
29
30 @staticmethod
31 def _extract_urls(webpage):
32 for tag, key in ((r'(?:script|iframe)', 'src'), ('input', 'value')):
33 # <input value=URL> is used by hyland.com
34 # if we find <iframe>, dont look for <input>
35 ret = re.findall(
36 r'<%s[^>]+?%s=["\']((?:https?:)?//(?:content\.jwplatform|cdn\.jwplayer)\.com/players/[a-zA-Z0-9]{8})' % (tag, key),
37 webpage)
38 if ret:
39 return ret
40 mobj = re.search(r'<div\b[^>]* data-video-jw-id="([a-zA-Z0-9]{8})"', webpage)
41 if mobj:
42 return [f'jwplatform:{mobj.group(1)}']
43
44 def _real_extract(self, url):
45 url, smuggled_data = unsmuggle_url(url, {})
46 self._initialize_geo_bypass({
47 'countries': smuggled_data.get('geo_countries'),
48 })
49 video_id = self._match_id(url)
50 json_data = self._download_json('https://cdn.jwplayer.com/v2/media/' + video_id, video_id)
51 return self._parse_jwplayer_data(json_data, video_id)