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.

80 lines
3.5 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\.)?audimedia\.tv/(?:en|de)/vid/(?P<id>[^/?#]+)'
  11. _TEST = {
  12. 'url': 'https://audimedia.tv/en/vid/60-seconds-of-audi-sport-104-2015-wec-bahrain-rookie-test',
  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(r'<script[^>]+class="amtv-embed"[^>]+id="([^"]+)"', webpage, 'raw payload')
  31. _, stage_mode, video_id, lang = raw_payload.split('-')
  32. # TODO: handle s and e stage_mode (live streams and ended live streams)
  33. if stage_mode not in ('s', 'e'):
  34. request = sanitized_Request(
  35. 'https://audimedia.tv/api/video/v1/videos/%s?embed[]=video_versions&embed[]=thumbnail_image&where[content_language_iso]=%s' % (video_id, lang),
  36. headers={'X-Auth-Token': self._AUTH_TOKEN})
  37. json_data = self._download_json(request, video_id)['results']
  38. formats = []
  39. stream_url_hls = json_data.get('stream_url_hls')
  40. if stream_url_hls:
  41. formats.extend(self._extract_m3u8_formats(
  42. stream_url_hls, video_id, 'mp4',
  43. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  44. stream_url_hds = json_data.get('stream_url_hds')
  45. if stream_url_hds:
  46. formats.extend(self._extract_f4m_formats(
  47. stream_url_hds + '?hdcore=3.4.0',
  48. video_id, f4m_id='hds', fatal=False))
  49. for video_version in json_data.get('video_versions'):
  50. video_version_url = video_version.get('download_url') or video_version.get('stream_url')
  51. if not video_version_url:
  52. continue
  53. formats.append({
  54. 'url': video_version_url,
  55. 'width': int_or_none(video_version.get('width')),
  56. 'height': int_or_none(video_version.get('height')),
  57. 'abr': int_or_none(video_version.get('audio_bitrate')),
  58. 'vbr': int_or_none(video_version.get('video_bitrate')),
  59. })
  60. self._sort_formats(formats)
  61. return {
  62. 'id': video_id,
  63. 'title': json_data['title'],
  64. 'description': json_data.get('subtitle'),
  65. 'thumbnail': json_data.get('thumbnail_image', {}).get('file'),
  66. 'timestamp': parse_iso8601(json_data.get('publication_date')),
  67. 'duration': int_or_none(json_data.get('duration')),
  68. 'view_count': int_or_none(json_data.get('view_count')),
  69. 'formats': formats,
  70. }