]>
Commit | Line | Data |
---|---|---|
b3eaeded | 1 | import re |
add96eb9 | 2 | import urllib.parse |
b3eaeded RA |
3 | |
4 | from .turner import TurnerBaseIE | |
b6f78d76 RA |
5 | from ..utils import ( |
6 | float_or_none, | |
7 | int_or_none, | |
8 | strip_or_none, | |
9 | ) | |
b3eaeded RA |
10 | |
11 | ||
12 | class TBSIE(TurnerBaseIE): | |
01b052b2 | 13 | _VALID_URL = r'https?://(?:www\.)?(?P<site>tbs|tntdrama)\.com(?P<path>/(?:movies|watchtnt|watchtbs|shows/[^/]+/(?:clips|season-\d+/episode-\d+))/(?P<id>[^/?#]+))' |
b3eaeded | 14 | _TESTS = [{ |
b6f78d76 | 15 | 'url': 'http://www.tntdrama.com/shows/the-alienist/clips/monster', |
b3eaeded | 16 | 'info_dict': { |
b6f78d76 | 17 | 'id': '8d384cde33b89f3a43ce5329de42903ed5099887', |
b3eaeded | 18 | 'ext': 'mp4', |
b6f78d76 RA |
19 | 'title': 'Monster', |
20 | 'description': 'Get a first look at the theatrical trailer for TNT’s highly anticipated new psychological thriller The Alienist, which premieres January 22 on TNT.', | |
21 | 'timestamp': 1508175329, | |
22 | 'upload_date': '20171016', | |
85f5a74b | 23 | }, |
b6f78d76 RA |
24 | 'params': { |
25 | # m3u8 download | |
26 | 'skip_download': True, | |
add96eb9 | 27 | }, |
b3eaeded | 28 | }, { |
b6f78d76 RA |
29 | 'url': 'http://www.tbs.com/shows/search-party/season-1/episode-1/explicit-the-mysterious-disappearance-of-the-girl-no-one-knew', |
30 | 'only_matching': True, | |
31 | }, { | |
32 | 'url': 'http://www.tntdrama.com/movies/star-wars-a-new-hope', | |
33 | 'only_matching': True, | |
b3eaeded RA |
34 | }] |
35 | ||
36 | def _real_extract(self, url): | |
5ad28e7f | 37 | site, path, display_id = self._match_valid_url(url).groups() |
b3eaeded | 38 | webpage = self._download_webpage(url, display_id) |
e0d42dd4 | 39 | drupal_settings = self._parse_json(self._search_regex( |
b6f78d76 | 40 | r'<script[^>]+?data-drupal-selector="drupal-settings-json"[^>]*?>({.+?})</script>', |
e0d42dd4 | 41 | webpage, 'drupal setting'), display_id) |
add96eb9 | 42 | is_live = 'watchtnt' in path or 'watchtbs' in path |
43 | video_data = next(v for v in drupal_settings['turner_playlist'] if is_live or v.get('url') == path) | |
b6f78d76 RA |
44 | |
45 | media_id = video_data['mediaID'] | |
46 | title = video_data['title'] | |
add96eb9 | 47 | tokenizer_query = urllib.parse.parse_qs(urllib.parse.urlparse( |
e0d42dd4 | 48 | drupal_settings['ngtv_token_url']).query) |
b6f78d76 | 49 | |
e0d42dd4 RA |
50 | info = self._extract_ngtv_info( |
51 | media_id, tokenizer_query, { | |
52 | 'url': url, | |
53 | 'site_name': site[:3].upper(), | |
add96eb9 | 54 | 'auth_required': video_data.get('authRequired') == '1' or is_live, |
55 | 'is_live': is_live, | |
e0d42dd4 | 56 | }) |
b6f78d76 RA |
57 | |
58 | thumbnails = [] | |
59 | for image_id, image in video_data.get('images', {}).items(): | |
60 | image_url = image.get('url') | |
61 | if not image_url or image.get('type') != 'video': | |
62 | continue | |
63 | i = { | |
64 | 'id': image_id, | |
65 | 'url': image_url, | |
66 | } | |
67 | mobj = re.search(r'(\d+)x(\d+)', image_url) | |
68 | if mobj: | |
69 | i.update({ | |
70 | 'width': int(mobj.group(1)), | |
71 | 'height': int(mobj.group(2)), | |
72 | }) | |
73 | thumbnails.append(i) | |
74 | ||
e0d42dd4 | 75 | info.update({ |
b6f78d76 RA |
76 | 'id': media_id, |
77 | 'title': title, | |
78 | 'description': strip_or_none(video_data.get('descriptionNoTags') or video_data.get('shortDescriptionNoTags')), | |
e0d42dd4 | 79 | 'duration': float_or_none(video_data.get('duration')) or info.get('duration'), |
b6f78d76 RA |
80 | 'timestamp': int_or_none(video_data.get('created')), |
81 | 'season_number': int_or_none(video_data.get('season')), | |
82 | 'episode_number': int_or_none(video_data.get('episode')), | |
b6f78d76 | 83 | 'thumbnails': thumbnails, |
add96eb9 | 84 | 'is_live': is_live, |
e0d42dd4 RA |
85 | }) |
86 | return info |