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