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.

118 lines
4.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .theplatform import ThePlatformIE
  4. from ..utils import (
  5. int_or_none,
  6. parse_age_limit,
  7. try_get,
  8. update_url_query,
  9. )
  10. class AMCNetworksIE(ThePlatformIE):
  11. _VALID_URL = r'https?://(?:www\.)?(?:amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?:movies|shows(?:/[^/]+)+)/(?P<id>[^/?#]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.ifc.com/shows/maron/season-04/episode-01/step-1',
  14. 'md5': '',
  15. 'info_dict': {
  16. 'id': 's3MX01Nl4vPH',
  17. 'ext': 'mp4',
  18. 'title': 'Maron - Season 4 - Step 1',
  19. 'description': 'In denial about his current situation, Marc is reluctantly convinced by his friends to enter rehab. Starring Marc Maron and Constance Zimmer.',
  20. 'age_limit': 17,
  21. 'upload_date': '20160505',
  22. 'timestamp': 1462468831,
  23. 'uploader': 'AMCN',
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. },
  29. 'skip': 'Requires TV provider accounts',
  30. }, {
  31. 'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://www.ifc.com/movies/chaos',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://www.bbcamerica.com/shows/doctor-who/full-episodes/the-power-of-the-daleks/episode-01-episode-1-color-version',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/thin-tervention',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://www.wetv.com/shows/la-hair/videos/season-05/episode-09-episode-9-2/episode-9-sneak-peek-3',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1',
  53. 'only_matching': True,
  54. }]
  55. def _real_extract(self, url):
  56. display_id = self._match_id(url)
  57. webpage = self._download_webpage(url, display_id)
  58. query = {
  59. 'mbr': 'true',
  60. 'manifest': 'm3u',
  61. }
  62. media_url = self._search_regex(
  63. r'window\.platformLinkURL\s*=\s*[\'"]([^\'"]+)',
  64. webpage, 'media url')
  65. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  66. r'link\.theplatform\.com/s/([^?]+)',
  67. media_url, 'theplatform_path'), display_id)
  68. info = self._parse_theplatform_metadata(theplatform_metadata)
  69. video_id = theplatform_metadata['pid']
  70. title = theplatform_metadata['title']
  71. rating = try_get(
  72. theplatform_metadata, lambda x: x['ratings'][0]['rating'])
  73. auth_required = self._search_regex(
  74. r'window\.authRequired\s*=\s*(true|false);',
  75. webpage, 'auth required')
  76. if auth_required == 'true':
  77. requestor_id = self._search_regex(
  78. r'window\.requestor_id\s*=\s*[\'"]([^\'"]+)',
  79. webpage, 'requestor id')
  80. resource = self._get_mvpd_resource(
  81. requestor_id, title, video_id, rating)
  82. query['auth'] = self._extract_mvpd_auth(
  83. url, video_id, requestor_id, resource)
  84. media_url = update_url_query(media_url, query)
  85. formats, subtitles = self._extract_theplatform_smil(
  86. media_url, video_id)
  87. self._sort_formats(formats)
  88. info.update({
  89. 'id': video_id,
  90. 'subtitles': subtitles,
  91. 'formats': formats,
  92. 'age_limit': parse_age_limit(parse_age_limit(rating)),
  93. })
  94. ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
  95. if ns_keys:
  96. ns = list(ns_keys)[0]
  97. series = theplatform_metadata.get(ns + '$show')
  98. season_number = int_or_none(
  99. theplatform_metadata.get(ns + '$season'))
  100. episode = theplatform_metadata.get(ns + '$episodeTitle')
  101. episode_number = int_or_none(
  102. theplatform_metadata.get(ns + '$episode'))
  103. if season_number:
  104. title = 'Season %d - %s' % (season_number, title)
  105. if series:
  106. title = '%s - %s' % (series, title)
  107. info.update({
  108. 'title': title,
  109. 'series': series,
  110. 'season_number': season_number,
  111. 'episode': episode,
  112. 'episode_number': episode_number,
  113. })
  114. return info