logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

jwplatform.py (1720B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import unsmuggle_url
  6. class JWPlatformIE(InfoExtractor):
  7. _VALID_URL = r'(?:https?://(?:content\.jwplatform|cdn\.jwplayer)\.com/(?:(?:feed|player|thumb|preview)s|jw6|v2/media)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
  8. _TESTS = [{
  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. 'url': 'https://cdn.jwplayer.com/players/nPripu9l-ALJ3XQCI.js',
  21. 'only_matching': True,
  22. }]
  23. @staticmethod
  24. def _extract_url(webpage):
  25. urls = JWPlatformIE._extract_urls(webpage)
  26. return urls[0] if urls else None
  27. @staticmethod
  28. def _extract_urls(webpage):
  29. return re.findall(
  30. r'<(?:script|iframe)[^>]+?src=["\']((?:https?:)?//(?:content\.jwplatform|cdn\.jwplayer)\.com/players/[a-zA-Z0-9]{8})',
  31. webpage)
  32. def _real_extract(self, url):
  33. url, smuggled_data = unsmuggle_url(url, {})
  34. self._initialize_geo_bypass({
  35. 'countries': smuggled_data.get('geo_countries'),
  36. })
  37. video_id = self._match_id(url)
  38. json_data = self._download_json('https://cdn.jwplayer.com/v2/media/' + video_id, video_id)
  39. return self._parse_jwplayer_data(json_data, video_id)