logo

youtube-dl

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

threeqsdn.py (6254B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_HTTPError
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. float_or_none,
  9. int_or_none,
  10. parse_iso8601,
  11. )
  12. class ThreeQSDNIE(InfoExtractor):
  13. IE_NAME = '3qsdn'
  14. IE_DESC = '3Q SDN'
  15. _VALID_URL = r'https?://playout\.3qsdn\.com/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
  16. _TESTS = [{
  17. # https://player.3qsdn.com/demo.html
  18. 'url': 'https://playout.3qsdn.com/7201c779-6b3c-11e7-a40e-002590c750be',
  19. 'md5': '64a57396b16fa011b15e0ea60edce918',
  20. 'info_dict': {
  21. 'id': '7201c779-6b3c-11e7-a40e-002590c750be',
  22. 'ext': 'mp4',
  23. 'title': 'Video Ads',
  24. 'is_live': False,
  25. 'description': 'Video Ads Demo',
  26. 'timestamp': 1500334803,
  27. 'upload_date': '20170717',
  28. 'duration': 888.032,
  29. 'subtitles': {
  30. 'eng': 'count:1',
  31. },
  32. },
  33. 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
  34. }, {
  35. # live video stream
  36. 'url': 'https://playout.3qsdn.com/66e68995-11ca-11e8-9273-002590c750be',
  37. 'info_dict': {
  38. 'id': '66e68995-11ca-11e8-9273-002590c750be',
  39. 'ext': 'mp4',
  40. 'title': 're:^66e68995-11ca-11e8-9273-002590c750be [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  41. 'is_live': True,
  42. },
  43. 'params': {
  44. 'skip_download': True, # m3u8 downloads
  45. },
  46. }, {
  47. # live audio stream
  48. 'url': 'http://playout.3qsdn.com/9edf36e0-6bf2-11e2-a16a-9acf09e2db48',
  49. 'only_matching': True,
  50. }, {
  51. # live audio stream with some 404 URLs
  52. 'url': 'http://playout.3qsdn.com/ac5c3186-777a-11e2-9c30-9acf09e2db48',
  53. 'only_matching': True,
  54. }, {
  55. # geo restricted with 'This content is not available in your country'
  56. 'url': 'http://playout.3qsdn.com/d63a3ffe-75e8-11e2-9c30-9acf09e2db48',
  57. 'only_matching': True,
  58. }, {
  59. # geo restricted with 'playout.3qsdn.com/forbidden'
  60. 'url': 'http://playout.3qsdn.com/8e330f26-6ae2-11e2-a16a-9acf09e2db48',
  61. 'only_matching': True,
  62. }, {
  63. # live video with rtmp link
  64. 'url': 'https://playout.3qsdn.com/6092bb9e-8f72-11e4-a173-002590c750be',
  65. 'only_matching': True,
  66. }, {
  67. # ondemand from http://www.philharmonie.tv/veranstaltung/26/
  68. 'url': 'http://playout.3qsdn.com/0280d6b9-1215-11e6-b427-0cc47a188158?protocol=http',
  69. 'only_matching': True,
  70. }, {
  71. # live video stream
  72. 'url': 'https://playout.3qsdn.com/d755d94b-4ab9-11e3-9162-0025907ad44f?js=true',
  73. 'only_matching': True,
  74. }]
  75. @staticmethod
  76. def _extract_url(webpage):
  77. mobj = re.search(
  78. r'<iframe[^>]+\b(?:data-)?src=(["\'])(?P<url>%s.*?)\1' % ThreeQSDNIE._VALID_URL, webpage)
  79. if mobj:
  80. return mobj.group('url')
  81. def _real_extract(self, url):
  82. video_id = self._match_id(url)
  83. try:
  84. config = self._download_json(
  85. url.replace('://playout.3qsdn.com/', '://playout.3qsdn.com/config/'), video_id)
  86. except ExtractorError as e:
  87. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
  88. self.raise_geo_restricted()
  89. raise
  90. live = config.get('streamContent') == 'live'
  91. aspect = float_or_none(config.get('aspect'))
  92. formats = []
  93. for source_type, source in (config.get('sources') or {}).items():
  94. if not source:
  95. continue
  96. if source_type == 'dash':
  97. formats.extend(self._extract_mpd_formats(
  98. source, video_id, mpd_id='mpd', fatal=False))
  99. elif source_type == 'hls':
  100. formats.extend(self._extract_m3u8_formats(
  101. source, video_id, 'mp4', 'm3u8' if live else 'm3u8_native',
  102. m3u8_id='hls', fatal=False))
  103. elif source_type == 'progressive':
  104. for s in source:
  105. src = s.get('src')
  106. if not (src and self._is_valid_url(src, video_id)):
  107. continue
  108. width = None
  109. format_id = ['http']
  110. ext = determine_ext(src)
  111. if ext:
  112. format_id.append(ext)
  113. height = int_or_none(s.get('height'))
  114. if height:
  115. format_id.append('%dp' % height)
  116. if aspect:
  117. width = int(height * aspect)
  118. formats.append({
  119. 'ext': ext,
  120. 'format_id': '-'.join(format_id),
  121. 'height': height,
  122. 'source_preference': 0,
  123. 'url': src,
  124. 'vcodec': 'none' if height == 0 else None,
  125. 'width': width,
  126. })
  127. for f in formats:
  128. if f.get('acodec') == 'none':
  129. f['preference'] = -40
  130. elif f.get('vcodec') == 'none':
  131. f['preference'] = -50
  132. self._sort_formats(formats, ('preference', 'width', 'height', 'source_preference', 'tbr', 'vbr', 'abr', 'ext', 'format_id'))
  133. subtitles = {}
  134. for subtitle in (config.get('subtitles') or []):
  135. src = subtitle.get('src')
  136. if not src:
  137. continue
  138. subtitles.setdefault(subtitle.get('label') or 'eng', []).append({
  139. 'url': src,
  140. })
  141. title = config.get('title') or video_id
  142. return {
  143. 'id': video_id,
  144. 'title': self._live_title(title) if live else title,
  145. 'thumbnail': config.get('poster') or None,
  146. 'description': config.get('description') or None,
  147. 'timestamp': parse_iso8601(config.get('upload_date')),
  148. 'duration': float_or_none(config.get('vlength')) or None,
  149. 'is_live': live,
  150. 'formats': formats,
  151. 'subtitles': subtitles,
  152. }