]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/trunews.py
debian/README.source: Change 'markup'.
[youtubedl] / youtube_dl / extractor / trunews.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5 dict_get,
6 float_or_none,
7 int_or_none,
8 unified_timestamp,
9 update_url_query,
10 url_or_none,
11 )
12
13
14 class TruNewsIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?trunews\.com/stream/(?P<id>[^/?#&]+)'
16 _TEST = {
17 'url': 'https://www.trunews.com/stream/will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
18 'md5': 'a19c024c3906ff954fac9b96ce66bb08',
19 'info_dict': {
20 'id': '5c5a21e65d3c196e1c0020cc',
21 'display_id': 'will-democrats-stage-a-circus-during-president-trump-s-state-of-the-union-speech',
22 'ext': 'mp4',
23 'title': "Will Democrats Stage a Circus During President Trump's State of the Union Speech?",
24 'description': 'md5:c583b72147cc92cf21f56a31aff7a670',
25 'duration': 3685,
26 'timestamp': 1549411440,
27 'upload_date': '20190206',
28 },
29 'add_ie': ['Zype'],
30 }
31
32 def _real_extract(self, url):
33 display_id = self._match_id(url)
34
35 video = self._download_json(
36 'https://api.zype.com/videos', display_id, query={
37 'app_key': 'PUVKp9WgGUb3-JUw6EqafLx8tFVP6VKZTWbUOR-HOm__g4fNDt1bCsm_LgYf_k9H',
38 'per_page': 1,
39 'active': 'true',
40 'friendly_title': display_id,
41 })['response'][0]
42
43 zype_id = video['_id']
44
45 thumbnails = []
46 thumbnails_list = video.get('thumbnails')
47 if isinstance(thumbnails_list, list):
48 for thumbnail in thumbnails_list:
49 if not isinstance(thumbnail, dict):
50 continue
51 thumbnail_url = url_or_none(thumbnail.get('url'))
52 if not thumbnail_url:
53 continue
54 thumbnails.append({
55 'url': thumbnail_url,
56 'width': int_or_none(thumbnail.get('width')),
57 'height': int_or_none(thumbnail.get('height')),
58 })
59
60 return {
61 '_type': 'url_transparent',
62 'url': update_url_query(
63 'https://player.zype.com/embed/%s.js' % zype_id,
64 {'api_key': 'X5XnahkjCwJrT_l5zUqypnaLEObotyvtUKJWWlONxDoHVjP8vqxlArLV8llxMbyt'}),
65 'ie_key': 'Zype',
66 'id': zype_id,
67 'display_id': display_id,
68 'title': video.get('title'),
69 'description': dict_get(video, ('description', 'ott_description', 'short_description')),
70 'duration': int_or_none(video.get('duration')),
71 'timestamp': unified_timestamp(video.get('published_at')),
72 'average_rating': float_or_none(video.get('rating')),
73 'view_count': int_or_none(video.get('request_count')),
74 'thumbnails': thumbnails,
75 }