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