]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tenplay.py
Update changelog.
[youtubedl] / youtube_dl / extractor / tenplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 float_or_none,
8 )
9
10
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',
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',
22 'uploader': 'TENplay',
23 },
24 'params': {
25 'skip_download': True, # Requires rtmpdump
26 }
27 }
28
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"]
34
35 def _real_extract(self, url):
36 webpage = self._download_webpage(url, url)
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')
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
56 tbr = int_or_none(rendition.get('encodingRate'), 1000)
57
58 formats.append({
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']),
66 'protocol': protocol,
67 'ext': ext,
68 'vcodec': rendition['videoCodec'].lower(),
69 'container': rendition['videoContainer'].lower(),
70 'url': url,
71 })
72 self._sort_formats(formats)
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'],
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')),
90 }