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.

75 lines
2.9 KiB

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