0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-23 02:25:11 +00:00
yt-dlp/yt_dlp/extractor/trutv.py

76 lines
2.5 KiB
Python
Raw Normal View History

2016-09-06 14:48:51 +00:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .turner import TurnerBaseIE
2019-02-06 18:38:10 +00:00
from ..utils import (
int_or_none,
parse_iso8601,
)
2016-09-06 14:48:51 +00:00
class TruTVIE(TurnerBaseIE):
2019-02-06 18:38:10 +00:00
_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+))'
2016-09-06 14:48:51 +00:00
_TEST = {
2019-02-06 18:38:10 +00:00
'url': 'https://www.trutv.com/shows/the-carbonaro-effect/videos/sunlight-activated-flower.html',
2016-09-06 14:48:51 +00:00
'info_dict': {
2019-02-06 18:38:10 +00:00
'id': 'f16c03beec1e84cd7d1a51f11d8fcc29124cc7f1',
2016-09-06 14:48:51 +00:00
'ext': 'mp4',
2019-02-06 18:38:10 +00:00
'title': 'Sunlight-Activated Flower',
'description': "A customer is stunned when he sees Michael's sunlight-activated flower.",
},
'params': {
# m3u8 download
'skip_download': True,
},
2016-09-06 14:48:51 +00:00
}
def _real_extract(self, url):
2019-02-06 18:38:10 +00:00
series_slug, clip_slug, video_id = re.match(self._VALID_URL, url).groups()
if video_id:
path = 'episode'
display_id = video_id
2016-09-06 14:48:51 +00:00
else:
2019-02-06 18:38:10 +00:00
path = 'series/clip'
display_id = clip_slug
data = self._download_json(
'https://api.trutv.com/v2/web/%s/%s/%s' % (path, series_slug, display_id),
display_id)
video_data = data['episode'] if video_id else data['info']
media_id = video_data['mediaId']
title = video_data['title'].strip()
info = self._extract_ngtv_info(
media_id, {}, {
'url': url,
'site_name': 'truTV',
2019-02-06 18:38:10 +00:00
'auth_required': video_data.get('isAuthRequired'),
2016-09-06 14:48:51 +00:00
})
2019-02-06 18:38:10 +00:00
thumbnails = []
for image in video_data.get('images', []):
image_url = image.get('srcUrl')
if not image_url:
continue
thumbnails.append({
'url': image_url,
'width': int_or_none(image.get('width')),
'height': int_or_none(image.get('height')),
})
info.update({
'id': media_id,
'display_id': display_id,
'title': title,
'description': video_data.get('description'),
'thumbnails': thumbnails,
'timestamp': parse_iso8601(video_data.get('publicationDate')),
'series': video_data.get('showTitle'),
'season_number': int_or_none(video_data.get('seasonNum')),
'episode_number': int_or_none(video_data.get('episodeNum')),
})
return info