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.

90 lines
3.6 KiB

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. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. float_or_none,
  7. )
  8. class TenPlayIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?ten(play)?\.com\.au/.+'
  10. _TEST = {
  11. 'url': 'http://tenplay.com.au/ten-insider/extra/season-2013/tenplay-tv-your-way',
  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',
  19. 'uploader': 'TENplay',
  20. },
  21. 'params': {
  22. 'skip_download': True, # Requires rtmpdump
  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. def _real_extract(self, url):
  31. webpage = self._download_webpage(url, url)
  32. video_id = self._html_search_regex(
  33. r'videoID: "(\d+?)"', webpage, 'video_id')
  34. api_token = self._html_search_regex(
  35. r'apiToken: "([a-zA-Z0-9-_\.]+?)"', webpage, 'api_token')
  36. title = self._html_search_regex(
  37. r'<meta property="og:title" content="\s*(.*?)\s*"\s*/?\s*>',
  38. webpage, 'title')
  39. 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)
  40. formats = []
  41. for rendition in json['renditions']:
  42. url = rendition['remoteUrl'] or rendition['url']
  43. protocol = 'rtmp' if url.startswith('rtmp') else 'http'
  44. ext = 'flv' if protocol == 'rtmp' else rendition['videoContainer'].lower()
  45. if protocol == 'rtmp':
  46. url = url.replace('&mp4:', '')
  47. tbr = int_or_none(rendition.get('encodingRate'), 1000)
  48. formats.append({
  49. 'format_id': '_'.join(
  50. ['rtmp', rendition['videoContainer'].lower(),
  51. rendition['videoCodec'].lower(), '%sk' % tbr]),
  52. 'width': int_or_none(rendition['frameWidth']),
  53. 'height': int_or_none(rendition['frameHeight']),
  54. 'tbr': tbr,
  55. 'filesize': int_or_none(rendition['size']),
  56. 'protocol': protocol,
  57. 'ext': ext,
  58. 'vcodec': rendition['videoCodec'].lower(),
  59. 'container': rendition['videoContainer'].lower(),
  60. 'url': url,
  61. })
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'display_id': json['referenceId'],
  66. 'title': json['name'],
  67. 'description': json['shortDescription'] or json['longDescription'],
  68. 'formats': formats,
  69. 'thumbnails': [{
  70. 'url': json['videoStillURL']
  71. }, {
  72. 'url': json['thumbnailURL']
  73. }],
  74. 'thumbnail': json['videoStillURL'],
  75. 'duration': float_or_none(json.get('length'), 1000),
  76. 'timestamp': float_or_none(json.get('creationDate'), 1000),
  77. 'uploader': json.get('customFields', {}).get('production_company_distributor') or 'TENplay',
  78. 'view_count': int_or_none(json.get('playsTotal')),
  79. }