amcnetworks.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import re
  2. from .theplatform import ThePlatformIE
  3. from ..utils import (
  4. int_or_none,
  5. parse_age_limit,
  6. try_get,
  7. update_url_query,
  8. )
  9. class AMCNetworksIE(ThePlatformIE): # XXX: Do not subclass from concrete IE
  10. _VALID_URL = r'https?://(?:www\.)?(?P<site>amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?P<id>(?:movies|shows(?:/[^/]+)+)/[^/?#&]+)'
  11. _TESTS = [{
  12. 'url': 'https://www.bbcamerica.com/shows/the-graham-norton-show/videos/tina-feys-adorable-airline-themed-family-dinner--51631',
  13. 'info_dict': {
  14. 'id': '4Lq1dzOnZGt0',
  15. 'ext': 'mp4',
  16. 'title': "The Graham Norton Show - Season 28 - Tina Fey's Adorable Airline-Themed Family Dinner",
  17. 'description': "It turns out child stewardesses are very generous with the wine! All-new episodes of 'The Graham Norton Show' premiere Fridays at 11/10c on BBC America.",
  18. 'upload_date': '20201120',
  19. 'timestamp': 1605904350,
  20. 'uploader': 'AMCN',
  21. },
  22. 'params': {
  23. # m3u8 download
  24. 'skip_download': True,
  25. },
  26. }, {
  27. 'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'http://www.ifc.com/movies/chaos',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'http://www.bbcamerica.com/shows/doctor-who/full-episodes/the-power-of-the-daleks/episode-01-episode-1-color-version',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/thin-tervention',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'http://www.wetv.com/shows/la-hair/videos/season-05/episode-09-episode-9-2/episode-9-sneak-peek-3',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1',
  49. 'only_matching': True,
  50. }]
  51. _REQUESTOR_ID_MAP = {
  52. 'amc': 'AMC',
  53. 'bbcamerica': 'BBCA',
  54. 'ifc': 'IFC',
  55. 'sundancetv': 'SUNDANCE',
  56. 'wetv': 'WETV',
  57. }
  58. def _real_extract(self, url):
  59. site, display_id = self._match_valid_url(url).groups()
  60. requestor_id = self._REQUESTOR_ID_MAP[site]
  61. page_data = self._download_json(
  62. 'https://content-delivery-gw.svc.ds.amcn.com/api/v2/content/amcn/%s/url/%s'
  63. % (requestor_id.lower(), display_id), display_id)['data']
  64. properties = page_data.get('properties') or {}
  65. query = {
  66. 'mbr': 'true',
  67. 'manifest': 'm3u',
  68. }
  69. video_player_count = 0
  70. try:
  71. for v in page_data['children']:
  72. if v.get('type') == 'video-player':
  73. releasePid = v['properties']['currentVideo']['meta']['releasePid']
  74. tp_path = 'M_UwQC/' + releasePid
  75. media_url = 'https://link.theplatform.com/s/' + tp_path
  76. video_player_count += 1
  77. except KeyError:
  78. pass
  79. if video_player_count > 1:
  80. self.report_warning(
  81. 'The JSON data has %d video players. Only one will be extracted' % video_player_count)
  82. # Fall back to videoPid if releasePid not found.
  83. # TODO: Fall back to videoPid if releasePid manifest uses DRM.
  84. if not video_player_count:
  85. tp_path = 'M_UwQC/media/' + properties['videoPid']
  86. media_url = 'https://link.theplatform.com/s/' + tp_path
  87. theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id)
  88. info = self._parse_theplatform_metadata(theplatform_metadata)
  89. video_id = theplatform_metadata['pid']
  90. title = theplatform_metadata['title']
  91. rating = try_get(
  92. theplatform_metadata, lambda x: x['ratings'][0]['rating'])
  93. video_category = properties.get('videoCategory')
  94. if video_category and video_category.endswith('-Auth'):
  95. resource = self._get_mvpd_resource(
  96. requestor_id, title, video_id, rating)
  97. query['auth'] = self._extract_mvpd_auth(
  98. url, video_id, requestor_id, resource)
  99. media_url = update_url_query(media_url, query)
  100. formats, subtitles = self._extract_theplatform_smil(
  101. media_url, video_id)
  102. thumbnails = []
  103. thumbnail_urls = [properties.get('imageDesktop')]
  104. if 'thumbnail' in info:
  105. thumbnail_urls.append(info.pop('thumbnail'))
  106. for thumbnail_url in thumbnail_urls:
  107. if not thumbnail_url:
  108. continue
  109. mobj = re.search(r'(\d+)x(\d+)', thumbnail_url)
  110. thumbnails.append({
  111. 'url': thumbnail_url,
  112. 'width': int(mobj.group(1)) if mobj else None,
  113. 'height': int(mobj.group(2)) if mobj else None,
  114. })
  115. info.update({
  116. 'age_limit': parse_age_limit(rating),
  117. 'formats': formats,
  118. 'id': video_id,
  119. 'subtitles': subtitles,
  120. 'thumbnails': thumbnails,
  121. })
  122. ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
  123. if ns_keys:
  124. ns = list(ns_keys)[0]
  125. episode = theplatform_metadata.get(ns + '$episodeTitle') or None
  126. episode_number = int_or_none(
  127. theplatform_metadata.get(ns + '$episode'))
  128. season_number = int_or_none(
  129. theplatform_metadata.get(ns + '$season'))
  130. series = theplatform_metadata.get(ns + '$show') or None
  131. info.update({
  132. 'episode': episode,
  133. 'episode_number': episode_number,
  134. 'season_number': season_number,
  135. 'series': series,
  136. })
  137. return info