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.

113 lines
4.5 KiB

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