]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/trutv.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / trutv.py
CommitLineData
c33c962a
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .turner import TurnerBaseIE
241c5d7d
RA
7from ..utils import (
8 int_or_none,
9 parse_iso8601,
10)
c33c962a
RA
11
12
13class TruTVIE(TurnerBaseIE):
241c5d7d 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+))'
c33c962a 15 _TEST = {
241c5d7d 16 'url': 'https://www.trutv.com/shows/the-carbonaro-effect/videos/sunlight-activated-flower.html',
c33c962a 17 'info_dict': {
241c5d7d 18 'id': 'f16c03beec1e84cd7d1a51f11d8fcc29124cc7f1',
c33c962a 19 'ext': 'mp4',
241c5d7d
RA
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 },
c33c962a
RA
27 }
28
29 def _real_extract(self, url):
241c5d7d
RA
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
c33c962a 35 else:
241c5d7d
RA
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, {}, {
c38f0681
RA
48 'url': url,
49 'site_name': 'truTV',
241c5d7d 50 'auth_required': video_data.get('isAuthRequired'),
c33c962a 51 })
241c5d7d
RA
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