]>
Commit | Line | Data |
---|---|---|
1d0668ed AMW |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
1d0668ed | 4 | from .common import InfoExtractor |
d41ebe14 S |
5 | from ..utils import ( |
6 | int_or_none, | |
7 | float_or_none, | |
8 | ) | |
1d0668ed | 9 | |
04c77a54 | 10 | |
1d0668ed AMW |
11 | class TenPlayIE(InfoExtractor): |
12 | _VALID_URL = r'https?://(?:www\.)?ten(play)?\.com\.au/.+' | |
13 | _TEST = { | |
14 | 'url': 'http://tenplay.com.au/ten-insider/extra/season-2013/tenplay-tv-your-way', | |
1d0668ed AMW |
15 | 'info_dict': { |
16 | 'id': '2695695426001', | |
17 | 'ext': 'flv', | |
18 | 'title': 'TENplay: TV your way', | |
19 | 'description': 'Welcome to a new TV experience. Enjoy a taste of the TENplay benefits.', | |
20 | 'timestamp': 1380150606.889, | |
21 | 'upload_date': '20130925', | |
04c77a54 PH |
22 | 'uploader': 'TENplay', |
23 | }, | |
24 | 'params': { | |
25 | 'skip_download': True, # Requires rtmpdump | |
1d0668ed AMW |
26 | } |
27 | } | |
28 | ||
04c77a54 PH |
29 | _video_fields = [ |
30 | "id", "name", "shortDescription", "longDescription", "creationDate", | |
31 | "publishedDate", "lastModifiedDate", "customFields", "videoStillURL", | |
32 | "thumbnailURL", "referenceId", "length", "playsTotal", | |
33 | "playsTrailingWeek", "renditions", "captioning", "startDate", "endDate"] | |
1d0668ed AMW |
34 | |
35 | def _real_extract(self, url): | |
36 | webpage = self._download_webpage(url, url) | |
04c77a54 PH |
37 | video_id = self._html_search_regex( |
38 | r'videoID: "(\d+?)"', webpage, 'video_id') | |
39 | api_token = self._html_search_regex( | |
40 | r'apiToken: "([a-zA-Z0-9-_\.]+?)"', webpage, 'api_token') | |
41 | title = self._html_search_regex( | |
42 | r'<meta property="og:title" content="\s*(.*?)\s*"\s*/?\s*>', | |
43 | webpage, 'title') | |
1d0668ed AMW |
44 | |
45 | json = self._download_json('https://api.brightcove.com/services/library?command=find_video_by_id&video_id=%s&token=%s&video_fields=%s' % (video_id, api_token, ','.join(self._video_fields)), title) | |
46 | ||
47 | formats = [] | |
48 | for rendition in json['renditions']: | |
49 | url = rendition['remoteUrl'] or rendition['url'] | |
50 | protocol = 'rtmp' if url.startswith('rtmp') else 'http' | |
51 | ext = 'flv' if protocol == 'rtmp' else rendition['videoContainer'].lower() | |
52 | ||
53 | if protocol == 'rtmp': | |
54 | url = url.replace('&mp4:', '') | |
55 | ||
d41ebe14 S |
56 | tbr = int_or_none(rendition.get('encodingRate'), 1000) |
57 | ||
1d0668ed | 58 | formats.append({ |
d41ebe14 S |
59 | 'format_id': '_'.join( |
60 | ['rtmp', rendition['videoContainer'].lower(), | |
61 | rendition['videoCodec'].lower(), '%sk' % tbr]), | |
62 | 'width': int_or_none(rendition['frameWidth']), | |
63 | 'height': int_or_none(rendition['frameHeight']), | |
64 | 'tbr': tbr, | |
65 | 'filesize': int_or_none(rendition['size']), | |
1d0668ed AMW |
66 | 'protocol': protocol, |
67 | 'ext': ext, | |
68 | 'vcodec': rendition['videoCodec'].lower(), | |
69 | 'container': rendition['videoContainer'].lower(), | |
04c77a54 PH |
70 | 'url': url, |
71 | }) | |
d41ebe14 | 72 | self._sort_formats(formats) |
1d0668ed AMW |
73 | |
74 | return { | |
75 | 'id': video_id, | |
76 | 'display_id': json['referenceId'], | |
77 | 'title': json['name'], | |
78 | 'description': json['shortDescription'] or json['longDescription'], | |
79 | 'formats': formats, | |
80 | 'thumbnails': [{ | |
81 | 'url': json['videoStillURL'] | |
82 | }, { | |
83 | 'url': json['thumbnailURL'] | |
84 | }], | |
85 | 'thumbnail': json['videoStillURL'], | |
d41ebe14 S |
86 | 'duration': float_or_none(json.get('length'), 1000), |
87 | 'timestamp': float_or_none(json.get('creationDate'), 1000), | |
88 | 'uploader': json.get('customFields', {}).get('production_company_distributor') or 'TENplay', | |
89 | 'view_count': int_or_none(json.get('playsTotal')), | |
1d0668ed | 90 | } |