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