logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

audimedia.py (4026B)


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