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