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.

82 lines
3.4 KiB

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