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.

72 lines
3.2 KiB

  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': 'c9dda6aac8f814352ad2aee8899b1612',
  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. }
  20. _video_fields = ["id","name","shortDescription","longDescription","creationDate","publishedDate","lastModifiedDate","customFields","videoStillURL","thumbnailURL","referenceId","length","playsTotal","playsTrailingWeek","renditions","captioning","startDate","endDate"]
  21. def _real_extract(self, url):
  22. webpage = self._download_webpage(url, url)
  23. video_id = self._html_search_regex(r'videoID: "(\d+?)"', webpage, 'video_id')
  24. api_token = self._html_search_regex(r'apiToken: "([a-zA-Z0-9-_\.]+?)"', webpage, 'api_token')
  25. title = self._html_search_regex(r'<meta property="og:title" content="\s*(.*?)\s*"\s*/?\s*>', webpage, 'title')
  26. 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)
  27. formats = []
  28. for rendition in json['renditions']:
  29. url = rendition['remoteUrl'] or rendition['url']
  30. protocol = 'rtmp' if url.startswith('rtmp') else 'http'
  31. ext = 'flv' if protocol == 'rtmp' else rendition['videoContainer'].lower()
  32. if protocol == 'rtmp':
  33. url = url.replace('&mp4:', '')
  34. formats.append({
  35. 'format_id': '_'.join(['rtmp', rendition['videoContainer'].lower(), rendition['videoCodec'].lower()]),
  36. 'width': rendition['frameWidth'],
  37. 'height': rendition['frameHeight'],
  38. 'tbr': rendition['encodingRate'] / 1024,
  39. 'filesize': rendition['size'],
  40. 'protocol': protocol,
  41. 'ext': ext,
  42. 'vcodec': rendition['videoCodec'].lower(),
  43. 'container': rendition['videoContainer'].lower(),
  44. 'url': url
  45. })
  46. return {
  47. 'id': video_id,
  48. 'display_id': json['referenceId'],
  49. 'title': json['name'],
  50. 'description': json['shortDescription'] or json['longDescription'],
  51. 'formats': formats,
  52. 'thumbnails': [{
  53. 'url': json['videoStillURL']
  54. }, {
  55. 'url': json['thumbnailURL']
  56. }],
  57. 'thumbnail': json['videoStillURL'],
  58. 'duration': json['length'] / 1000,
  59. 'timestamp': float(json['creationDate']) / 1000,
  60. 'uploader': json['customFields']['production_company_distributor'] if 'production_company_distributor' in json['customFields'] else 'TENplay',
  61. 'view_count': json['playsTotal']
  62. }