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