jwplatform.py 2.6 KB

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