audimedia.py 3.8 KB

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