bravotv.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import re
  2. from .adobepass import AdobePassIE
  3. from ..utils import (
  4. smuggle_url,
  5. update_url_query,
  6. int_or_none,
  7. float_or_none,
  8. try_get,
  9. dict_get,
  10. )
  11. class BravoTVIE(AdobePassIE):
  12. _VALID_URL = r'https?://(?:www\.)?(?P<req_id>bravotv|oxygen)\.com/(?:[^/]+/)+(?P<id>[^/?#]+)'
  13. _TESTS = [{
  14. 'url': 'https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-is',
  15. 'md5': 'e34684cfea2a96cd2ee1ef3a60909de9',
  16. 'info_dict': {
  17. 'id': 'epL0pmK1kQlT',
  18. 'ext': 'mp4',
  19. 'title': 'The Top Chef Season 16 Winner Is...',
  20. 'description': 'Find out who takes the title of Top Chef!',
  21. 'uploader': 'NBCU-BRAV',
  22. 'upload_date': '20190314',
  23. 'timestamp': 1552591860,
  24. 'season_number': 16,
  25. 'episode_number': 15,
  26. 'series': 'Top Chef',
  27. 'episode': 'The Top Chef Season 16 Winner Is...',
  28. 'duration': 190.0,
  29. }
  30. }, {
  31. 'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'https://www.oxygen.com/in-ice-cold-blood/season-2/episode-16/videos/handling-the-horwitz-house-after-the-murder-season-2',
  35. 'only_matching': True,
  36. }]
  37. def _real_extract(self, url):
  38. site, display_id = self._match_valid_url(url).groups()
  39. webpage = self._download_webpage(url, display_id)
  40. settings = self._parse_json(self._search_regex(
  41. r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>({.+?})</script>', webpage, 'drupal settings'),
  42. display_id)
  43. info = {}
  44. query = {
  45. 'mbr': 'true',
  46. }
  47. account_pid, release_pid = [None] * 2
  48. tve = settings.get('ls_tve')
  49. if tve:
  50. query['manifest'] = 'm3u'
  51. mobj = re.search(r'<[^>]+id="pdk-player"[^>]+data-url=["\']?(?:https?:)?//player\.theplatform\.com/p/([^/]+)/(?:[^/]+/)*select/([^?#&"\']+)', webpage)
  52. if mobj:
  53. account_pid, tp_path = mobj.groups()
  54. release_pid = tp_path.strip('/').split('/')[-1]
  55. else:
  56. account_pid = 'HNK2IC'
  57. tp_path = release_pid = tve['release_pid']
  58. if tve.get('entitlement') == 'auth':
  59. adobe_pass = settings.get('tve_adobe_auth', {})
  60. if site == 'bravotv':
  61. site = 'bravo'
  62. resource = self._get_mvpd_resource(
  63. adobe_pass.get('adobePassResourceId') or site,
  64. tve['title'], release_pid, tve.get('rating'))
  65. query['auth'] = self._extract_mvpd_auth(
  66. url, release_pid,
  67. adobe_pass.get('adobePassRequestorId') or site, resource)
  68. else:
  69. shared_playlist = settings['ls_playlist']
  70. account_pid = shared_playlist['account_pid']
  71. metadata = shared_playlist['video_metadata'][shared_playlist['default_clip']]
  72. tp_path = release_pid = metadata.get('release_pid')
  73. if not release_pid:
  74. release_pid = metadata['guid']
  75. tp_path = 'media/guid/2140479951/' + release_pid
  76. info.update({
  77. 'title': metadata['title'],
  78. 'description': metadata.get('description'),
  79. 'season_number': int_or_none(metadata.get('season_num')),
  80. 'episode_number': int_or_none(metadata.get('episode_num')),
  81. })
  82. query['switch'] = 'progressive'
  83. tp_url = 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path)
  84. tp_metadata = self._download_json(
  85. update_url_query(tp_url, {'format': 'preview'}),
  86. display_id, fatal=False)
  87. if tp_metadata:
  88. info.update({
  89. 'title': tp_metadata.get('title'),
  90. 'description': tp_metadata.get('description'),
  91. 'duration': float_or_none(tp_metadata.get('duration'), 1000),
  92. 'season_number': int_or_none(
  93. dict_get(tp_metadata, ('pl1$seasonNumber', 'nbcu$seasonNumber'))),
  94. 'episode_number': int_or_none(
  95. dict_get(tp_metadata, ('pl1$episodeNumber', 'nbcu$episodeNumber'))),
  96. # For some reason the series is sometimes wrapped into a single element array.
  97. 'series': try_get(
  98. dict_get(tp_metadata, ('pl1$show', 'nbcu$show')),
  99. lambda x: x[0] if isinstance(x, list) else x,
  100. expected_type=str),
  101. 'episode': dict_get(
  102. tp_metadata, ('pl1$episodeName', 'nbcu$episodeName', 'title')),
  103. })
  104. info.update({
  105. '_type': 'url_transparent',
  106. 'id': release_pid,
  107. 'url': smuggle_url(update_url_query(tp_url, query), {'force_smil_url': True}),
  108. 'ie_key': 'ThePlatform',
  109. })
  110. return info