]>
Commit | Line | Data |
---|---|---|
b5ddee8c RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
29f7c58a | 4 | import re |
5 | ||
b5ddee8c RA |
6 | from .theplatform import ThePlatformIE |
7 | from ..utils import ( | |
837e56c8 | 8 | int_or_none, |
9682666b S |
9 | parse_age_limit, |
10 | try_get, | |
11 | update_url_query, | |
b5ddee8c RA |
12 | ) |
13 | ||
14 | ||
15 | class AMCNetworksIE(ThePlatformIE): | |
29f7c58a | 16 | _VALID_URL = r'https?://(?:www\.)?(?P<site>amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?P<id>(?:movies|shows(?:/[^/]+)+)/[^/?#&]+)' |
b5ddee8c | 17 | _TESTS = [{ |
29f7c58a | 18 | 'url': 'https://www.bbcamerica.com/shows/the-graham-norton-show/videos/tina-feys-adorable-airline-themed-family-dinner--51631', |
b5ddee8c | 19 | 'info_dict': { |
29f7c58a | 20 | 'id': '4Lq1dzOnZGt0', |
b5ddee8c | 21 | 'ext': 'mp4', |
29f7c58a | 22 | 'title': "The Graham Norton Show - Season 28 - Tina Fey's Adorable Airline-Themed Family Dinner", |
23 | '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.", | |
24 | 'upload_date': '20201120', | |
25 | 'timestamp': 1605904350, | |
b5ddee8c RA |
26 | 'uploader': 'AMCN', |
27 | }, | |
28 | 'params': { | |
29 | # m3u8 download | |
30 | 'skip_download': True, | |
31 | }, | |
32 | }, { | |
33 | 'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge', | |
34 | 'only_matching': True, | |
35 | }, { | |
36 | 'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot', | |
37 | 'only_matching': True, | |
38 | }, { | |
39 | 'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal', | |
40 | 'only_matching': True, | |
41 | }, { | |
42 | 'url': 'http://www.ifc.com/movies/chaos', | |
43 | 'only_matching': True, | |
1d6ae562 YCH |
44 | }, { |
45 | 'url': 'http://www.bbcamerica.com/shows/doctor-who/full-episodes/the-power-of-the-daleks/episode-01-episode-1-color-version', | |
46 | 'only_matching': True, | |
231bcd0b S |
47 | }, { |
48 | 'url': 'http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/thin-tervention', | |
49 | 'only_matching': True, | |
50 | }, { | |
51 | 'url': 'http://www.wetv.com/shows/la-hair/videos/season-05/episode-09-episode-9-2/episode-9-sneak-peek-3', | |
52 | 'only_matching': True, | |
466000fc RA |
53 | }, { |
54 | 'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1', | |
55 | 'only_matching': True, | |
b5ddee8c | 56 | }] |
29f7c58a | 57 | _REQUESTOR_ID_MAP = { |
58 | 'amc': 'AMC', | |
59 | 'bbcamerica': 'BBCA', | |
60 | 'ifc': 'IFC', | |
61 | 'sundancetv': 'SUNDANCE', | |
62 | 'wetv': 'WETV', | |
63 | } | |
b5ddee8c RA |
64 | |
65 | def _real_extract(self, url): | |
29f7c58a | 66 | site, display_id = re.match(self._VALID_URL, url).groups() |
67 | requestor_id = self._REQUESTOR_ID_MAP[site] | |
68 | properties = self._download_json( | |
69 | 'https://content-delivery-gw.svc.ds.amcn.com/api/v2/content/amcn/%s/url/%s' % (requestor_id.lower(), display_id), | |
70 | display_id)['data']['properties'] | |
b5ddee8c RA |
71 | query = { |
72 | 'mbr': 'true', | |
73 | 'manifest': 'm3u', | |
74 | } | |
29f7c58a | 75 | tp_path = 'M_UwQC/media/' + properties['videoPid'] |
76 | media_url = 'https://link.theplatform.com/s/' + tp_path | |
77 | theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id) | |
b5ddee8c RA |
78 | info = self._parse_theplatform_metadata(theplatform_metadata) |
79 | video_id = theplatform_metadata['pid'] | |
80 | title = theplatform_metadata['title'] | |
9682666b S |
81 | rating = try_get( |
82 | theplatform_metadata, lambda x: x['ratings'][0]['rating']) | |
29f7c58a | 83 | video_category = properties.get('videoCategory') |
84 | if video_category and video_category.endswith('-Auth'): | |
1bd05345 RA |
85 | resource = self._get_mvpd_resource( |
86 | requestor_id, title, video_id, rating) | |
87 | query['auth'] = self._extract_mvpd_auth( | |
88 | url, video_id, requestor_id, resource) | |
b5ddee8c | 89 | media_url = update_url_query(media_url, query) |
1bd05345 RA |
90 | formats, subtitles = self._extract_theplatform_smil( |
91 | media_url, video_id) | |
b5ddee8c RA |
92 | self._sort_formats(formats) |
93 | info.update({ | |
94 | 'id': video_id, | |
2cabee2a | 95 | 'subtitles': subtitles, |
b5ddee8c RA |
96 | 'formats': formats, |
97 | 'age_limit': parse_age_limit(parse_age_limit(rating)), | |
98 | }) | |
837e56c8 RA |
99 | ns_keys = theplatform_metadata.get('$xmlns', {}).keys() |
100 | if ns_keys: | |
101 | ns = list(ns_keys)[0] | |
102 | series = theplatform_metadata.get(ns + '$show') | |
1bd05345 RA |
103 | season_number = int_or_none( |
104 | theplatform_metadata.get(ns + '$season')) | |
837e56c8 | 105 | episode = theplatform_metadata.get(ns + '$episodeTitle') |
1bd05345 RA |
106 | episode_number = int_or_none( |
107 | theplatform_metadata.get(ns + '$episode')) | |
837e56c8 RA |
108 | if season_number: |
109 | title = 'Season %d - %s' % (season_number, title) | |
110 | if series: | |
111 | title = '%s - %s' % (series, title) | |
112 | info.update({ | |
113 | 'title': title, | |
114 | 'series': series, | |
115 | 'season_number': season_number, | |
116 | 'episode': episode, | |
117 | 'episode_number': episode_number, | |
118 | }) | |
b5ddee8c | 119 | return info |