playwire.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. dict_get,
  6. float_or_none,
  7. )
  8. class PlaywireIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:config|cdn)\.playwire\.com(?:/v2)?/(?P<publisher_id>\d+)/(?:videos/v2|embed|config)/(?P<id>\d+)'
  10. _TESTS = [{
  11. 'url': 'http://config.playwire.com/14907/videos/v2/3353705/player.json',
  12. 'md5': 'e6398701e3595888125729eaa2329ed9',
  13. 'info_dict': {
  14. 'id': '3353705',
  15. 'ext': 'mp4',
  16. 'title': 'S04_RM_UCL_Rus',
  17. 'thumbnail': 're:^https?://.*\.png$',
  18. 'duration': 145.94,
  19. },
  20. }, {
  21. # Multiple resolutions while bitrates missing
  22. 'url': 'http://cdn.playwire.com/11625/embed/85228.html',
  23. 'only_matching': True,
  24. }, {
  25. 'url': 'http://config.playwire.com/12421/videos/v2/3389892/zeus.json',
  26. 'only_matching': True,
  27. }, {
  28. 'url': 'http://cdn.playwire.com/v2/12342/config/1532636.json',
  29. 'only_matching': True,
  30. }]
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. publisher_id, video_id = mobj.group('publisher_id'), mobj.group('id')
  34. player = self._download_json(
  35. 'http://config.playwire.com/%s/videos/v2/%s/zeus.json' % (publisher_id, video_id),
  36. video_id)
  37. title = player['settings']['title']
  38. duration = float_or_none(player.get('duration'), 1000)
  39. content = player['content']
  40. thumbnail = content.get('poster')
  41. src = content['media']['f4m']
  42. formats = self._extract_f4m_formats(src, video_id, assume_f4mv2=True)
  43. for a_format in formats:
  44. if not dict_get(a_format, ['tbr', 'width', 'height']):
  45. a_format['quality'] = 1 if '-hd.' in a_format['url'] else 0
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'thumbnail': thumbnail,
  51. 'duration': duration,
  52. 'formats': formats,
  53. }