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.

89 lines
3.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_iso8601,
  7. sanitized_Request,
  8. )
  9. class AudiMediaIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?audi-mediacenter\.com/(?:en|de)/audimediatv/(?P<id>[^/?#]+)'
  11. _TEST = {
  12. 'url': 'https://www.audi-mediacenter.com/en/audimediatv/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test-1467',
  13. 'md5': '79a8b71c46d49042609795ab59779b66',
  14. 'info_dict': {
  15. 'id': '1565',
  16. 'ext': 'mp4',
  17. 'title': '60 Seconds of Audi Sport 104/2015 - WEC Bahrain, Rookie Test',
  18. 'description': 'md5:60e5d30a78ced725f7b8d34370762941',
  19. 'upload_date': '20151124',
  20. 'timestamp': 1448354940,
  21. 'duration': 74022,
  22. 'view_count': int,
  23. }
  24. }
  25. # extracted from https://audimedia.tv/assets/embed/embedded-player.js (dataSourceAuthToken)
  26. _AUTH_TOKEN = 'e25b42847dba18c6c8816d5d8ce94c326e06823ebf0859ed164b3ba169be97f2'
  27. def _real_extract(self, url):
  28. display_id = self._match_id(url)
  29. webpage = self._download_webpage(url, display_id)
  30. raw_payload = self._search_regex([
  31. r'class="amtv-embed"[^>]+id="([^"]+)"',
  32. r'class=\\"amtv-embed\\"[^>]+id=\\"([^"]+)\\"',
  33. ], webpage, 'raw payload')
  34. _, stage_mode, video_id, lang = raw_payload.split('-')
  35. # TODO: handle s and e stage_mode (live streams and ended live streams)
  36. if stage_mode not in ('s', 'e'):
  37. request = sanitized_Request(
  38. 'https://audimedia.tv/api/video/v1/videos/%s?embed[]=video_versions&embed[]=thumbnail_image&where[content_language_iso]=%s' % (video_id, lang),
  39. headers={'X-Auth-Token': self._AUTH_TOKEN})
  40. json_data = self._download_json(request, video_id)['results']
  41. formats = []
  42. stream_url_hls = json_data.get('stream_url_hls')
  43. if stream_url_hls:
  44. formats.extend(self._extract_m3u8_formats(
  45. stream_url_hls, video_id, 'mp4',
  46. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  47. stream_url_hds = json_data.get('stream_url_hds')
  48. if stream_url_hds:
  49. formats.extend(self._extract_f4m_formats(
  50. stream_url_hds + '?hdcore=3.4.0',
  51. video_id, f4m_id='hds', fatal=False))
  52. for video_version in json_data.get('video_versions'):
  53. video_version_url = video_version.get('download_url') or video_version.get('stream_url')
  54. if not video_version_url:
  55. continue
  56. f = {
  57. 'url': video_version_url,
  58. 'width': int_or_none(video_version.get('width')),
  59. 'height': int_or_none(video_version.get('height')),
  60. 'abr': int_or_none(video_version.get('audio_bitrate')),
  61. 'vbr': int_or_none(video_version.get('video_bitrate')),
  62. }
  63. bitrate = self._search_regex(r'(\d+)k', video_version_url, 'bitrate', default=None)
  64. if bitrate:
  65. f.update({
  66. 'format_id': 'http-%s' % bitrate,
  67. })
  68. formats.append(f)
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'title': json_data['title'],
  73. 'description': json_data.get('subtitle'),
  74. 'thumbnail': json_data.get('thumbnail_image', {}).get('file'),
  75. 'timestamp': parse_iso8601(json_data.get('publication_date')),
  76. 'duration': int_or_none(json_data.get('duration')),
  77. 'view_count': int_or_none(json_data.get('view_count')),
  78. 'formats': formats,
  79. }