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.

78 lines
2.6 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. xpath_text,
  6. float_or_none,
  7. int_or_none,
  8. )
  9. class PlaywireIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:config|cdn)\.playwire\.com(?:/v2)?/(?P<publisher_id>\d+)/(?:videos/v2|embed|config)/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'http://config.playwire.com/14907/videos/v2/3353705/player.json',
  13. 'md5': 'e6398701e3595888125729eaa2329ed9',
  14. 'info_dict': {
  15. 'id': '3353705',
  16. 'ext': 'mp4',
  17. 'title': 'S04_RM_UCL_Rus',
  18. 'thumbnail': 're:^https?://.*\.png$',
  19. 'duration': 145.94,
  20. },
  21. }, {
  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. f4m = self._download_xml(src, video_id)
  43. base_url = xpath_text(f4m, './{http://ns.adobe.com/f4m/1.0}baseURL', 'base url', fatal=True)
  44. formats = []
  45. for media in f4m.findall('./{http://ns.adobe.com/f4m/1.0}media'):
  46. media_url = media.get('url')
  47. if not media_url:
  48. continue
  49. tbr = int_or_none(media.get('bitrate'))
  50. width = int_or_none(media.get('width'))
  51. height = int_or_none(media.get('height'))
  52. f = {
  53. 'url': '%s/%s' % (base_url, media.attrib['url']),
  54. 'tbr': tbr,
  55. 'width': width,
  56. 'height': height,
  57. }
  58. if not (tbr or width or height):
  59. f['quality'] = 1 if '-hd.' in media_url else 0
  60. formats.append(f)
  61. self._sort_formats(formats)
  62. return {
  63. 'id': video_id,
  64. 'title': title,
  65. 'thumbnail': thumbnail,
  66. 'duration': duration,
  67. 'formats': formats,
  68. }