You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.4 KiB

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