playwire.py 2.4 KB

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