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