You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.1 KiB

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