bravotv.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. from .adobepass import AdobePassIE
  2. from ..networking import HEADRequest
  3. from ..utils import (
  4. extract_attributes,
  5. float_or_none,
  6. get_element_html_by_class,
  7. int_or_none,
  8. merge_dicts,
  9. parse_age_limit,
  10. remove_end,
  11. str_or_none,
  12. traverse_obj,
  13. unescapeHTML,
  14. unified_timestamp,
  15. update_url_query,
  16. url_or_none,
  17. )
  18. class BravoTVIE(AdobePassIE):
  19. _VALID_URL = r'https?://(?:www\.)?(?P<site>bravotv|oxygen)\.com/(?:[^/]+/)+(?P<id>[^/?#]+)'
  20. _TESTS = [{
  21. 'url': 'https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-is',
  22. 'info_dict': {
  23. 'id': '3923059',
  24. 'ext': 'mp4',
  25. 'title': 'The Top Chef Season 16 Winner Is...',
  26. 'description': 'Find out who takes the title of Top Chef!',
  27. 'upload_date': '20190314',
  28. 'timestamp': 1552591860,
  29. 'season_number': 16,
  30. 'episode_number': 15,
  31. 'series': 'Top Chef',
  32. 'episode': 'The Top Chef Season 16 Winner Is...',
  33. 'duration': 190.357,
  34. 'season': 'Season 16',
  35. 'thumbnail': r're:^https://.+\.jpg',
  36. },
  37. 'params': {'skip_download': 'm3u8'},
  38. }, {
  39. 'url': 'https://www.bravotv.com/top-chef/season-20/episode-1/london-calling',
  40. 'info_dict': {
  41. 'id': '9000234570',
  42. 'ext': 'mp4',
  43. 'title': 'London Calling',
  44. 'description': 'md5:5af95a8cbac1856bd10e7562f86bb759',
  45. 'upload_date': '20230310',
  46. 'timestamp': 1678410000,
  47. 'season_number': 20,
  48. 'episode_number': 1,
  49. 'series': 'Top Chef',
  50. 'episode': 'London Calling',
  51. 'duration': 3266.03,
  52. 'season': 'Season 20',
  53. 'chapters': 'count:7',
  54. 'thumbnail': r're:^https://.+\.jpg',
  55. 'age_limit': 14,
  56. },
  57. 'params': {'skip_download': 'm3u8'},
  58. 'skip': 'This video requires AdobePass MSO credentials',
  59. }, {
  60. 'url': 'https://www.oxygen.com/in-ice-cold-blood/season-1/closing-night',
  61. 'info_dict': {
  62. 'id': '3692045',
  63. 'ext': 'mp4',
  64. 'title': 'Closing Night',
  65. 'description': 'md5:3170065c5c2f19548d72a4cbc254af63',
  66. 'upload_date': '20180401',
  67. 'timestamp': 1522623600,
  68. 'season_number': 1,
  69. 'episode_number': 1,
  70. 'series': 'In Ice Cold Blood',
  71. 'episode': 'Closing Night',
  72. 'duration': 2629.051,
  73. 'season': 'Season 1',
  74. 'chapters': 'count:6',
  75. 'thumbnail': r're:^https://.+\.jpg',
  76. 'age_limit': 14,
  77. },
  78. 'params': {'skip_download': 'm3u8'},
  79. 'skip': 'This video requires AdobePass MSO credentials',
  80. }, {
  81. 'url': 'https://www.oxygen.com/in-ice-cold-blood/season-2/episode-16/videos/handling-the-horwitz-house-after-the-murder-season-2',
  82. 'info_dict': {
  83. 'id': '3974019',
  84. 'ext': 'mp4',
  85. 'title': '\'Handling The Horwitz House After The Murder (Season 2, Episode 16)',
  86. 'description': 'md5:f9d638dd6946a1c1c0533a9c6100eae5',
  87. 'upload_date': '20190617',
  88. 'timestamp': 1560790800,
  89. 'season_number': 2,
  90. 'episode_number': 16,
  91. 'series': 'In Ice Cold Blood',
  92. 'episode': '\'Handling The Horwitz House After The Murder (Season 2, Episode 16)',
  93. 'duration': 68.235,
  94. 'season': 'Season 2',
  95. 'thumbnail': r're:^https://.+\.jpg',
  96. 'age_limit': 14,
  97. },
  98. 'params': {'skip_download': 'm3u8'},
  99. }, {
  100. 'url': 'https://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1',
  101. 'only_matching': True,
  102. }]
  103. def _real_extract(self, url):
  104. site, display_id = self._match_valid_url(url).group('site', 'id')
  105. webpage = self._download_webpage(url, display_id)
  106. settings = self._search_json(
  107. r'<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>', webpage, 'settings', display_id)
  108. tve = extract_attributes(get_element_html_by_class('tve-video-deck-app', webpage) or '')
  109. query = {
  110. 'manifest': 'm3u',
  111. 'formats': 'm3u,mpeg4',
  112. }
  113. if tve:
  114. account_pid = tve.get('data-mpx-media-account-pid') or 'HNK2IC'
  115. account_id = tve['data-mpx-media-account-id']
  116. metadata = self._parse_json(
  117. tve.get('data-normalized-video', ''), display_id, fatal=False, transform_source=unescapeHTML)
  118. video_id = tve.get('data-guid') or metadata['guid']
  119. if tve.get('data-entitlement') == 'auth':
  120. auth = traverse_obj(settings, ('tve_adobe_auth', {dict})) or {}
  121. site = remove_end(site, 'tv')
  122. release_pid = tve['data-release-pid']
  123. resource = self._get_mvpd_resource(
  124. tve.get('data-adobe-pass-resource-id') or auth.get('adobePassResourceId') or site,
  125. tve['data-title'], release_pid, tve.get('data-rating'))
  126. query.update({
  127. 'switch': 'HLSServiceSecure',
  128. 'auth': self._extract_mvpd_auth(
  129. url, release_pid, auth.get('adobePassRequestorId') or site, resource),
  130. })
  131. else:
  132. ls_playlist = traverse_obj(settings, ('ls_playlist', ..., {dict}), get_all=False) or {}
  133. account_pid = ls_playlist.get('mpxMediaAccountPid') or 'PHSl-B'
  134. account_id = ls_playlist['mpxMediaAccountId']
  135. video_id = ls_playlist['defaultGuid']
  136. metadata = traverse_obj(
  137. ls_playlist, ('videos', lambda _, v: v['guid'] == video_id, {dict}), get_all=False)
  138. tp_url = f'https://link.theplatform.com/s/{account_pid}/media/guid/{account_id}/{video_id}'
  139. tp_metadata = self._download_json(
  140. update_url_query(tp_url, {'format': 'preview'}), video_id, fatal=False)
  141. seconds_or_none = lambda x: float_or_none(x, 1000)
  142. chapters = traverse_obj(tp_metadata, ('chapters', ..., {
  143. 'start_time': ('startTime', {seconds_or_none}),
  144. 'end_time': ('endTime', {seconds_or_none}),
  145. }))
  146. # prune pointless single chapters that span the entire duration from short videos
  147. if len(chapters) == 1 and not traverse_obj(chapters, (0, 'end_time')):
  148. chapters = None
  149. m3u8_url = self._request_webpage(HEADRequest(
  150. update_url_query(f'{tp_url}/stream.m3u8', query)), video_id, 'Checking m3u8 URL').url
  151. if 'mpeg_cenc' in m3u8_url:
  152. self.report_drm(video_id)
  153. formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, 'mp4', m3u8_id='hls')
  154. return {
  155. 'id': video_id,
  156. 'formats': formats,
  157. 'subtitles': subtitles,
  158. 'chapters': chapters,
  159. **merge_dicts(traverse_obj(tp_metadata, {
  160. 'title': 'title',
  161. 'description': 'description',
  162. 'duration': ('duration', {seconds_or_none}),
  163. 'timestamp': ('pubDate', {seconds_or_none}),
  164. 'season_number': (('pl1$seasonNumber', 'nbcu$seasonNumber'), {int_or_none}),
  165. 'episode_number': (('pl1$episodeNumber', 'nbcu$episodeNumber'), {int_or_none}),
  166. 'series': (('pl1$show', 'nbcu$show'), (None, ...), {str}),
  167. 'episode': (('title', 'pl1$episodeNumber', 'nbcu$episodeNumber'), {str_or_none}),
  168. 'age_limit': ('ratings', ..., 'rating', {parse_age_limit}),
  169. }, get_all=False), traverse_obj(metadata, {
  170. 'title': 'title',
  171. 'description': 'description',
  172. 'duration': ('durationInSeconds', {int_or_none}),
  173. 'timestamp': ('airDate', {unified_timestamp}),
  174. 'thumbnail': ('thumbnailUrl', {url_or_none}),
  175. 'season_number': ('seasonNumber', {int_or_none}),
  176. 'episode_number': ('episodeNumber', {int_or_none}),
  177. 'episode': 'episodeTitle',
  178. 'series': 'show',
  179. })),
  180. }