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.

71 lines
2.7 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. m3u8_formats = self._extract_m3u8_formats(source_url, video_id, 'mp4', 'm3u8_native', fatal=None)
  41. if m3u8_formats:
  42. formats.extend(m3u8_formats)
  43. elif source_type.startswith('audio'):
  44. formats.append({
  45. 'url': source_url,
  46. 'vcodec': 'none',
  47. })
  48. else:
  49. formats.append({
  50. 'url': source_url,
  51. 'width': int_or_none(source.get('width')),
  52. 'height': int_or_none(source.get('height')),
  53. })
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'title': video_data['title'],
  58. 'description': video_data.get('description'),
  59. 'thumbnail': self._proto_relative_url(video_data.get('image')),
  60. 'timestamp': int_or_none(video_data.get('pubdate')),
  61. 'subtitles': subtitles,
  62. 'formats': formats,
  63. }