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.

81 lines
3.3 KiB

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