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