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.

84 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .adobepass import AdobePassIE
  5. from ..utils import (
  6. smuggle_url,
  7. update_url_query,
  8. int_or_none,
  9. )
  10. class BravoTVIE(AdobePassIE):
  11. _VALID_URL = r'https?://(?:www\.)?bravotv\.com/(?:[^/]+/)+(?P<id>[^/?#]+)'
  12. _TESTS = [{
  13. 'url': 'https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-is',
  14. 'md5': 'e34684cfea2a96cd2ee1ef3a60909de9',
  15. 'info_dict': {
  16. 'id': 'epL0pmK1kQlT',
  17. 'ext': 'mp4',
  18. 'title': 'The Top Chef Season 16 Winner Is...',
  19. 'description': 'Find out who takes the title of Top Chef!',
  20. 'uploader': 'NBCU-BRAV',
  21. 'upload_date': '20190314',
  22. 'timestamp': 1552591860,
  23. }
  24. }, {
  25. 'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. display_id = self._match_id(url)
  30. webpage = self._download_webpage(url, display_id)
  31. settings = self._parse_json(self._search_regex(
  32. r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>({.+?})</script>', webpage, 'drupal settings'),
  33. display_id)
  34. info = {}
  35. query = {
  36. 'mbr': 'true',
  37. }
  38. account_pid, release_pid = [None] * 2
  39. tve = settings.get('ls_tve')
  40. if tve:
  41. query['manifest'] = 'm3u'
  42. mobj = re.search(r'<[^>]+id="pdk-player"[^>]+data-url=["\']?(?:https?:)?//player\.theplatform\.com/p/([^/]+)/(?:[^/]+/)*select/([^?#&"\']+)', webpage)
  43. if mobj:
  44. account_pid, tp_path = mobj.groups()
  45. release_pid = tp_path.strip('/').split('/')[-1]
  46. else:
  47. account_pid = 'HNK2IC'
  48. tp_path = release_pid = tve['release_pid']
  49. if tve.get('entitlement') == 'auth':
  50. adobe_pass = settings.get('tve_adobe_auth', {})
  51. resource = self._get_mvpd_resource(
  52. adobe_pass.get('adobePassResourceId', 'bravo'),
  53. tve['title'], release_pid, tve.get('rating'))
  54. query['auth'] = self._extract_mvpd_auth(
  55. url, release_pid, adobe_pass.get('adobePassRequestorId', 'bravo'), resource)
  56. else:
  57. shared_playlist = settings['ls_playlist']
  58. account_pid = shared_playlist['account_pid']
  59. metadata = shared_playlist['video_metadata'][shared_playlist['default_clip']]
  60. tp_path = release_pid = metadata.get('release_pid')
  61. if not release_pid:
  62. release_pid = metadata['guid']
  63. tp_path = 'media/guid/2140479951/' + release_pid
  64. info.update({
  65. 'title': metadata['title'],
  66. 'description': metadata.get('description'),
  67. 'season_number': int_or_none(metadata.get('season_num')),
  68. 'episode_number': int_or_none(metadata.get('episode_num')),
  69. })
  70. query['switch'] = 'progressive'
  71. info.update({
  72. '_type': 'url_transparent',
  73. 'id': release_pid,
  74. 'url': smuggle_url(update_url_query(
  75. 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path),
  76. query), {'force_smil_url': True}),
  77. 'ie_key': 'ThePlatform',
  78. })
  79. return info