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.

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