]>
Commit | Line | Data |
---|---|---|
3ca3f77f U |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .turner import TurnerBaseIE | |
7 | from ..utils import ( | |
8 | int_or_none, | |
9 | parse_iso8601, | |
10 | ) | |
11 | ||
12 | ||
13 | class TruTVIE(TurnerBaseIE): | |
14 | _VALID_URL = r'https?://(?:www\.)?trutv\.com/(?:shows|full-episodes)/(?P<series_slug>[0-9A-Za-z-]+)/(?:videos/(?P<clip_slug>[0-9A-Za-z-]+)|(?P<id>\d+))' | |
15 | _TEST = { | |
16 | 'url': 'https://www.trutv.com/shows/the-carbonaro-effect/videos/sunlight-activated-flower.html', | |
17 | 'info_dict': { | |
18 | 'id': 'f16c03beec1e84cd7d1a51f11d8fcc29124cc7f1', | |
19 | 'ext': 'mp4', | |
20 | 'title': 'Sunlight-Activated Flower', | |
21 | 'description': "A customer is stunned when he sees Michael's sunlight-activated flower.", | |
22 | }, | |
23 | 'params': { | |
24 | # m3u8 download | |
25 | 'skip_download': True, | |
26 | }, | |
27 | } | |
28 | ||
29 | def _real_extract(self, url): | |
30 | series_slug, clip_slug, video_id = re.match(self._VALID_URL, url).groups() | |
31 | ||
32 | if video_id: | |
33 | path = 'episode' | |
34 | display_id = video_id | |
35 | else: | |
36 | path = 'series/clip' | |
37 | display_id = clip_slug | |
38 | ||
39 | data = self._download_json( | |
40 | 'https://api.trutv.com/v2/web/%s/%s/%s' % (path, series_slug, display_id), | |
41 | display_id) | |
42 | video_data = data['episode'] if video_id else data['info'] | |
43 | media_id = video_data['mediaId'] | |
44 | title = video_data['title'].strip() | |
45 | ||
46 | info = self._extract_ngtv_info( | |
47 | media_id, {}, { | |
48 | 'url': url, | |
49 | 'site_name': 'truTV', | |
50 | 'auth_required': video_data.get('isAuthRequired'), | |
51 | }) | |
52 | ||
53 | thumbnails = [] | |
54 | for image in video_data.get('images', []): | |
55 | image_url = image.get('srcUrl') | |
56 | if not image_url: | |
57 | continue | |
58 | thumbnails.append({ | |
59 | 'url': image_url, | |
60 | 'width': int_or_none(image.get('width')), | |
61 | 'height': int_or_none(image.get('height')), | |
62 | }) | |
63 | ||
64 | info.update({ | |
65 | 'id': media_id, | |
66 | 'display_id': display_id, | |
67 | 'title': title, | |
68 | 'description': video_data.get('description'), | |
69 | 'thumbnails': thumbnails, | |
70 | 'timestamp': parse_iso8601(video_data.get('publicationDate')), | |
71 | 'series': video_data.get('showTitle'), | |
72 | 'season_number': int_or_none(video_data.get('seasonNum')), | |
73 | 'episode_number': int_or_none(video_data.get('episodeNum')), | |
74 | }) | |
75 | return info |