]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/jwplatform.py
Fine tune the changelog.
[youtubedl] / youtube_dl / extractor / jwplatform.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import int_or_none
8
9
10 class JWPlatformIE(InfoExtractor):
11 _VALID_URL = r'(?:https?://content\.jwplatform\.com/(?:feeds|players|jw6)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
12 _TEST = {
13 'url': 'http://content.jwplatform.com/players/nPripu9l-ALJ3XQCI.js',
14 'md5': 'fa8899fa601eb7c83a64e9d568bdf325',
15 'info_dict': {
16 'id': 'nPripu9l',
17 'ext': 'mov',
18 'title': 'Big Buck Bunny Trailer',
19 'description': 'Big Buck Bunny is a short animated film by the Blender Institute. It is made using free and open source software.',
20 'upload_date': '20081127',
21 'timestamp': 1227796140,
22 }
23 }
24
25 @staticmethod
26 def _extract_url(webpage):
27 mobj = re.search(
28 r'<script[^>]+?src=["\'](?P<url>(?:https?:)?//content.jwplatform.com/players/[a-zA-Z0-9]{8})',
29 webpage)
30 if mobj:
31 return mobj.group('url')
32
33 def _real_extract(self, url):
34 video_id = self._match_id(url)
35 json_data = self._download_json('http://content.jwplatform.com/feeds/%s.json' % video_id, video_id)
36 video_data = json_data['playlist'][0]
37 subtitles = {}
38 for track in video_data['tracks']:
39 if track['kind'] == 'captions':
40 subtitles[track['label']] = [{'url': self._proto_relative_url(track['file'])}]
41
42 formats = []
43 for source in video_data['sources']:
44 source_url = self._proto_relative_url(source['file'])
45 source_type = source.get('type') or ''
46 if source_type == 'application/vnd.apple.mpegurl':
47 formats.extend(self._extract_m3u8_formats(
48 source_url, video_id, 'mp4', 'm3u8_native', fatal=False))
49 elif source_type.startswith('audio'):
50 formats.append({
51 'url': source_url,
52 'vcodec': 'none',
53 })
54 else:
55 formats.append({
56 'url': source_url,
57 'width': int_or_none(source.get('width')),
58 'height': int_or_none(source.get('height')),
59 })
60 self._sort_formats(formats)
61
62 return {
63 'id': video_id,
64 'title': video_data['title'],
65 'description': video_data.get('description'),
66 'thumbnail': self._proto_relative_url(video_data.get('image')),
67 'timestamp': int_or_none(video_data.get('pubdate')),
68 'subtitles': subtitles,
69 'formats': formats,
70 }