logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

amcnetworks.py (4967B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .theplatform import ThePlatformIE
  5. from ..utils import (
  6. int_or_none,
  7. parse_age_limit,
  8. try_get,
  9. update_url_query,
  10. )
  11. class AMCNetworksIE(ThePlatformIE):
  12. _VALID_URL = r'https?://(?:www\.)?(?P<site>amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?P<id>(?:movies|shows(?:/[^/]+)+)/[^/?#&]+)'
  13. _TESTS = [{
  14. 'url': 'https://www.bbcamerica.com/shows/the-graham-norton-show/videos/tina-feys-adorable-airline-themed-family-dinner--51631',
  15. 'info_dict': {
  16. 'id': '4Lq1dzOnZGt0',
  17. 'ext': 'mp4',
  18. 'title': "The Graham Norton Show - Season 28 - Tina Fey's Adorable Airline-Themed Family Dinner",
  19. '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.",
  20. 'upload_date': '20201120',
  21. 'timestamp': 1605904350,
  22. 'uploader': 'AMCN',
  23. },
  24. 'params': {
  25. # m3u8 download
  26. 'skip_download': True,
  27. },
  28. }, {
  29. 'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'http://www.ifc.com/movies/chaos',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'http://www.bbcamerica.com/shows/doctor-who/full-episodes/the-power-of-the-daleks/episode-01-episode-1-color-version',
  42. 'only_matching': True,
  43. }, {
  44. 'url': 'http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/thin-tervention',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://www.wetv.com/shows/la-hair/videos/season-05/episode-09-episode-9-2/episode-9-sneak-peek-3',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1',
  51. 'only_matching': True,
  52. }]
  53. _REQUESTOR_ID_MAP = {
  54. 'amc': 'AMC',
  55. 'bbcamerica': 'BBCA',
  56. 'ifc': 'IFC',
  57. 'sundancetv': 'SUNDANCE',
  58. 'wetv': 'WETV',
  59. }
  60. def _real_extract(self, url):
  61. site, display_id = re.match(self._VALID_URL, url).groups()
  62. requestor_id = self._REQUESTOR_ID_MAP[site]
  63. properties = self._download_json(
  64. 'https://content-delivery-gw.svc.ds.amcn.com/api/v2/content/amcn/%s/url/%s' % (requestor_id.lower(), display_id),
  65. display_id)['data']['properties']
  66. query = {
  67. 'mbr': 'true',
  68. 'manifest': 'm3u',
  69. }
  70. tp_path = 'M_UwQC/media/' + properties['videoPid']
  71. media_url = 'https://link.theplatform.com/s/' + tp_path
  72. theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id)
  73. info = self._parse_theplatform_metadata(theplatform_metadata)
  74. video_id = theplatform_metadata['pid']
  75. title = theplatform_metadata['title']
  76. rating = try_get(
  77. theplatform_metadata, lambda x: x['ratings'][0]['rating'])
  78. video_category = properties.get('videoCategory')
  79. if video_category and video_category.endswith('-Auth'):
  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