]>
Commit | Line | Data |
---|---|---|
29f7c58a | 1 | import re |
2 | ||
b5ddee8c RA |
3 | from .theplatform import ThePlatformIE |
4 | from ..utils import ( | |
837e56c8 | 5 | int_or_none, |
9682666b S |
6 | parse_age_limit, |
7 | try_get, | |
8 | update_url_query, | |
b5ddee8c RA |
9 | ) |
10 | ||
11 | ||
12 | class AMCNetworksIE(ThePlatformIE): | |
29f7c58a | 13 | _VALID_URL = r'https?://(?:www\.)?(?P<site>amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?P<id>(?:movies|shows(?:/[^/]+)+)/[^/?#&]+)' |
b5ddee8c | 14 | _TESTS = [{ |
29f7c58a | 15 | 'url': 'https://www.bbcamerica.com/shows/the-graham-norton-show/videos/tina-feys-adorable-airline-themed-family-dinner--51631', |
b5ddee8c | 16 | 'info_dict': { |
29f7c58a | 17 | 'id': '4Lq1dzOnZGt0', |
b5ddee8c | 18 | 'ext': 'mp4', |
29f7c58a | 19 | 'title': "The Graham Norton Show - Season 28 - Tina Fey's Adorable Airline-Themed Family Dinner", |
20 | '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.", | |
21 | 'upload_date': '20201120', | |
22 | 'timestamp': 1605904350, | |
b5ddee8c RA |
23 | 'uploader': 'AMCN', |
24 | }, | |
25 | 'params': { | |
26 | # m3u8 download | |
27 | 'skip_download': True, | |
28 | }, | |
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, | |
1d6ae562 YCH |
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, | |
231bcd0b S |
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, | |
466000fc RA |
50 | }, { |
51 | 'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1', | |
52 | 'only_matching': True, | |
b5ddee8c | 53 | }] |
29f7c58a | 54 | _REQUESTOR_ID_MAP = { |
55 | 'amc': 'AMC', | |
56 | 'bbcamerica': 'BBCA', | |
57 | 'ifc': 'IFC', | |
58 | 'sundancetv': 'SUNDANCE', | |
59 | 'wetv': 'WETV', | |
60 | } | |
b5ddee8c RA |
61 | |
62 | def _real_extract(self, url): | |
5ad28e7f | 63 | site, display_id = self._match_valid_url(url).groups() |
29f7c58a | 64 | requestor_id = self._REQUESTOR_ID_MAP[site] |
5c5fae6d | 65 | page_data = self._download_json( |
66 | 'https://content-delivery-gw.svc.ds.amcn.com/api/v2/content/amcn/%s/url/%s' | |
67 | % (requestor_id.lower(), display_id), display_id)['data'] | |
68 | properties = page_data.get('properties') or {} | |
b5ddee8c RA |
69 | query = { |
70 | 'mbr': 'true', | |
71 | 'manifest': 'm3u', | |
72 | } | |
5c5fae6d | 73 | |
74 | video_player_count = 0 | |
75 | try: | |
76 | for v in page_data['children']: | |
77 | if v.get('type') == 'video-player': | |
78 | releasePid = v['properties']['currentVideo']['meta']['releasePid'] | |
79 | tp_path = 'M_UwQC/' + releasePid | |
80 | media_url = 'https://link.theplatform.com/s/' + tp_path | |
81 | video_player_count += 1 | |
82 | except KeyError: | |
83 | pass | |
84 | if video_player_count > 1: | |
85 | self.report_warning( | |
86 | 'The JSON data has %d video players. Only one will be extracted' % video_player_count) | |
87 | ||
88 | # Fall back to videoPid if releasePid not found. | |
89 | # TODO: Fall back to videoPid if releasePid manifest uses DRM. | |
90 | if not video_player_count: | |
91 | tp_path = 'M_UwQC/media/' + properties['videoPid'] | |
92 | media_url = 'https://link.theplatform.com/s/' + tp_path | |
93 | ||
29f7c58a | 94 | theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id) |
b5ddee8c RA |
95 | info = self._parse_theplatform_metadata(theplatform_metadata) |
96 | video_id = theplatform_metadata['pid'] | |
97 | title = theplatform_metadata['title'] | |
9682666b S |
98 | rating = try_get( |
99 | theplatform_metadata, lambda x: x['ratings'][0]['rating']) | |
29f7c58a | 100 | video_category = properties.get('videoCategory') |
101 | if video_category and video_category.endswith('-Auth'): | |
1bd05345 RA |
102 | resource = self._get_mvpd_resource( |
103 | requestor_id, title, video_id, rating) | |
104 | query['auth'] = self._extract_mvpd_auth( | |
105 | url, video_id, requestor_id, resource) | |
b5ddee8c | 106 | media_url = update_url_query(media_url, query) |
1bd05345 RA |
107 | formats, subtitles = self._extract_theplatform_smil( |
108 | media_url, video_id) | |
b5ddee8c | 109 | self._sort_formats(formats) |
5c5fae6d | 110 | |
111 | thumbnails = [] | |
112 | thumbnail_urls = [properties.get('imageDesktop')] | |
113 | if 'thumbnail' in info: | |
114 | thumbnail_urls.append(info.pop('thumbnail')) | |
115 | for thumbnail_url in thumbnail_urls: | |
116 | if not thumbnail_url: | |
117 | continue | |
118 | mobj = re.search(r'(\d+)x(\d+)', thumbnail_url) | |
119 | thumbnails.append({ | |
120 | 'url': thumbnail_url, | |
121 | 'width': int(mobj.group(1)) if mobj else None, | |
122 | 'height': int(mobj.group(2)) if mobj else None, | |
123 | }) | |
124 | ||
b5ddee8c | 125 | info.update({ |
5c5fae6d | 126 | 'age_limit': parse_age_limit(rating), |
127 | 'formats': formats, | |
b5ddee8c | 128 | 'id': video_id, |
2cabee2a | 129 | 'subtitles': subtitles, |
5c5fae6d | 130 | 'thumbnails': thumbnails, |
b5ddee8c | 131 | }) |
837e56c8 RA |
132 | ns_keys = theplatform_metadata.get('$xmlns', {}).keys() |
133 | if ns_keys: | |
134 | ns = list(ns_keys)[0] | |
5c5fae6d | 135 | episode = theplatform_metadata.get(ns + '$episodeTitle') or None |
1bd05345 RA |
136 | episode_number = int_or_none( |
137 | theplatform_metadata.get(ns + '$episode')) | |
5c5fae6d | 138 | season_number = int_or_none( |
139 | theplatform_metadata.get(ns + '$season')) | |
140 | series = theplatform_metadata.get(ns + '$show') or None | |
837e56c8 | 141 | info.update({ |
837e56c8 RA |
142 | 'episode': episode, |
143 | 'episode_number': episode_number, | |
5c5fae6d | 144 | 'season_number': season_number, |
145 | 'series': series, | |
837e56c8 | 146 | }) |
b5ddee8c | 147 | return info |