mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-02-04 09:40:08 +09:00
Compare commits
No commits in common. "70f572585df5740da90feb518a93f10bb479cca2" and "170e1c19951ce6a87ce0e9157faa32b9a2efe708" have entirely different histories.
70f572585d
...
170e1c1995
@ -3,13 +3,10 @@ from __future__ import unicode_literals
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_HTTPError
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
determine_ext,
|
determine_ext,
|
||||||
ExtractorError,
|
js_to_json,
|
||||||
float_or_none,
|
mimetype2ext,
|
||||||
int_or_none,
|
|
||||||
parse_iso8601,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -18,35 +15,29 @@ class ThreeQSDNIE(InfoExtractor):
|
|||||||
IE_DESC = '3Q SDN'
|
IE_DESC = '3Q SDN'
|
||||||
_VALID_URL = r'https?://playout\.3qsdn\.com/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
|
_VALID_URL = r'https?://playout\.3qsdn\.com/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# https://player.3qsdn.com/demo.html
|
# ondemand from http://www.philharmonie.tv/veranstaltung/26/
|
||||||
'url': 'https://playout.3qsdn.com/7201c779-6b3c-11e7-a40e-002590c750be',
|
'url': 'http://playout.3qsdn.com/0280d6b9-1215-11e6-b427-0cc47a188158?protocol=http',
|
||||||
'md5': '64a57396b16fa011b15e0ea60edce918',
|
'md5': 'ab040e37bcfa2e0c079f92cb1dd7f6cd',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '7201c779-6b3c-11e7-a40e-002590c750be',
|
'id': '0280d6b9-1215-11e6-b427-0cc47a188158',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Video Ads',
|
'title': '0280d6b9-1215-11e6-b427-0cc47a188158',
|
||||||
'is_live': False,
|
'is_live': False,
|
||||||
'description': 'Video Ads Demo',
|
|
||||||
'timestamp': 1500334803,
|
|
||||||
'upload_date': '20170717',
|
|
||||||
'duration': 888.032,
|
|
||||||
'subtitles': {
|
|
||||||
'eng': 'count:1',
|
|
||||||
},
|
},
|
||||||
},
|
'expected_warnings': ['Failed to download MPD manifest', 'Failed to parse JSON'],
|
||||||
'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
|
|
||||||
}, {
|
}, {
|
||||||
# live video stream
|
# live video stream
|
||||||
'url': 'https://playout.3qsdn.com/66e68995-11ca-11e8-9273-002590c750be',
|
'url': 'https://playout.3qsdn.com/d755d94b-4ab9-11e3-9162-0025907ad44f?js=true',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '66e68995-11ca-11e8-9273-002590c750be',
|
'id': 'd755d94b-4ab9-11e3-9162-0025907ad44f',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 're:^66e68995-11ca-11e8-9273-002590c750be [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
|
'title': 're:^d755d94b-4ab9-11e3-9162-0025907ad44f [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
|
||||||
'is_live': True,
|
'is_live': True,
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'skip_download': True, # m3u8 downloads
|
'skip_download': True, # m3u8 downloads
|
||||||
},
|
},
|
||||||
|
'expected_warnings': ['Failed to download MPD manifest'],
|
||||||
}, {
|
}, {
|
||||||
# live audio stream
|
# live audio stream
|
||||||
'url': 'http://playout.3qsdn.com/9edf36e0-6bf2-11e2-a16a-9acf09e2db48',
|
'url': 'http://playout.3qsdn.com/9edf36e0-6bf2-11e2-a16a-9acf09e2db48',
|
||||||
@ -67,14 +58,6 @@ class ThreeQSDNIE(InfoExtractor):
|
|||||||
# live video with rtmp link
|
# live video with rtmp link
|
||||||
'url': 'https://playout.3qsdn.com/6092bb9e-8f72-11e4-a173-002590c750be',
|
'url': 'https://playout.3qsdn.com/6092bb9e-8f72-11e4-a173-002590c750be',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}, {
|
|
||||||
# ondemand from http://www.philharmonie.tv/veranstaltung/26/
|
|
||||||
'url': 'http://playout.3qsdn.com/0280d6b9-1215-11e6-b427-0cc47a188158?protocol=http',
|
|
||||||
'only_matching': True,
|
|
||||||
}, {
|
|
||||||
# live video stream
|
|
||||||
'url': 'https://playout.3qsdn.com/d755d94b-4ab9-11e3-9162-0025907ad44f?js=true',
|
|
||||||
'only_matching': True,
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -87,78 +70,73 @@ class ThreeQSDNIE(InfoExtractor):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
try:
|
js = self._download_webpage(
|
||||||
config = self._download_json(
|
'http://playout.3qsdn.com/%s' % video_id, video_id,
|
||||||
url.replace('://playout.3qsdn.com/', '://playout.3qsdn.com/config/'), video_id)
|
query={'js': 'true'})
|
||||||
except ExtractorError as e:
|
|
||||||
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
|
|
||||||
self.raise_geo_restricted()
|
|
||||||
raise
|
|
||||||
|
|
||||||
live = config.get('streamContent') == 'live'
|
if any(p in js for p in (
|
||||||
aspect = float_or_none(config.get('aspect'))
|
'>This content is not available in your country',
|
||||||
|
'playout.3qsdn.com/forbidden')):
|
||||||
|
self.raise_geo_restricted()
|
||||||
|
|
||||||
|
stream_content = self._search_regex(
|
||||||
|
r'streamContent\s*:\s*(["\'])(?P<content>.+?)\1', js,
|
||||||
|
'stream content', default='demand', group='content')
|
||||||
|
|
||||||
|
live = stream_content == 'live'
|
||||||
|
|
||||||
|
stream_type = self._search_regex(
|
||||||
|
r'streamType\s*:\s*(["\'])(?P<type>audio|video)\1', js,
|
||||||
|
'stream type', default='video', group='type')
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for source_type, source in (config.get('sources') or {}).items():
|
urls = set()
|
||||||
if not source:
|
|
||||||
continue
|
def extract_formats(item_url, item={}):
|
||||||
if source_type == 'dash':
|
if not item_url or item_url in urls:
|
||||||
|
return
|
||||||
|
urls.add(item_url)
|
||||||
|
ext = mimetype2ext(item.get('type')) or determine_ext(item_url, default_ext=None)
|
||||||
|
if ext == 'mpd':
|
||||||
formats.extend(self._extract_mpd_formats(
|
formats.extend(self._extract_mpd_formats(
|
||||||
source, video_id, mpd_id='mpd', fatal=False))
|
item_url, video_id, mpd_id='mpd', fatal=False))
|
||||||
elif source_type == 'hls':
|
elif ext == 'm3u8':
|
||||||
formats.extend(self._extract_m3u8_formats(
|
formats.extend(self._extract_m3u8_formats(
|
||||||
source, video_id, 'mp4', 'm3u8' if live else 'm3u8_native',
|
item_url, video_id, 'mp4',
|
||||||
|
entry_protocol='m3u8' if live else 'm3u8_native',
|
||||||
m3u8_id='hls', fatal=False))
|
m3u8_id='hls', fatal=False))
|
||||||
elif source_type == 'progressive':
|
elif ext == 'f4m':
|
||||||
for s in source:
|
formats.extend(self._extract_f4m_formats(
|
||||||
src = s.get('src')
|
item_url, video_id, f4m_id='hds', fatal=False))
|
||||||
if not (src and self._is_valid_url(src, video_id)):
|
else:
|
||||||
continue
|
if not self._is_valid_url(item_url, video_id):
|
||||||
width = None
|
return
|
||||||
format_id = ['http']
|
|
||||||
ext = determine_ext(src)
|
|
||||||
if ext:
|
|
||||||
format_id.append(ext)
|
|
||||||
height = int_or_none(s.get('height'))
|
|
||||||
if height:
|
|
||||||
format_id.append('%dp' % height)
|
|
||||||
if aspect:
|
|
||||||
width = int(height * aspect)
|
|
||||||
formats.append({
|
formats.append({
|
||||||
'ext': ext,
|
'url': item_url,
|
||||||
'format_id': '-'.join(format_id),
|
'format_id': item.get('quality'),
|
||||||
'height': height,
|
'ext': 'mp4' if item_url.startswith('rtsp') else ext,
|
||||||
'source_preference': 0,
|
'vcodec': 'none' if stream_type == 'audio' else None,
|
||||||
'url': src,
|
|
||||||
'vcodec': 'none' if height == 0 else None,
|
|
||||||
'width': width,
|
|
||||||
})
|
})
|
||||||
for f in formats:
|
|
||||||
if f.get('acodec') == 'none':
|
|
||||||
f['preference'] = -40
|
|
||||||
elif f.get('vcodec') == 'none':
|
|
||||||
f['preference'] = -50
|
|
||||||
self._sort_formats(formats, ('preference', 'width', 'height', 'source_preference', 'tbr', 'vbr', 'abr', 'ext', 'format_id'))
|
|
||||||
|
|
||||||
subtitles = {}
|
for item_js in re.findall(r'({[^{]*?\b(?:src|source)\s*:\s*["\'].+?})', js):
|
||||||
for subtitle in (config.get('subtitles') or []):
|
f = self._parse_json(
|
||||||
src = subtitle.get('src')
|
item_js, video_id, transform_source=js_to_json, fatal=False)
|
||||||
if not src:
|
if not f:
|
||||||
continue
|
continue
|
||||||
subtitles.setdefault(subtitle.get('label') or 'eng', []).append({
|
extract_formats(f.get('src'), f)
|
||||||
'url': src,
|
|
||||||
})
|
|
||||||
|
|
||||||
title = config.get('title') or video_id
|
# More relaxed version to collect additional URLs and acting
|
||||||
|
# as a future-proof fallback
|
||||||
|
for _, src in re.findall(r'\b(?:src|source)\s*:\s*(["\'])((?:https?|rtsp)://.+?)\1', js):
|
||||||
|
extract_formats(src)
|
||||||
|
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
title = self._live_title(video_id) if live else video_id
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': self._live_title(title) if live else title,
|
'title': title,
|
||||||
'thumbnail': config.get('poster') or None,
|
|
||||||
'description': config.get('description') or None,
|
|
||||||
'timestamp': parse_iso8601(config.get('upload_date')),
|
|
||||||
'duration': float_or_none(config.get('vlength')) or None,
|
|
||||||
'is_live': live,
|
'is_live': live,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'subtitles': subtitles,
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ from ..compat import (
|
|||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
clean_html,
|
clean_html,
|
||||||
dict_get,
|
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
@ -77,14 +76,14 @@ class TwitchBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Referer': page_url,
|
'Referer': page_url,
|
||||||
'Origin': 'https://www.twitch.tv',
|
'Origin': page_url,
|
||||||
'Content-Type': 'text/plain;charset=UTF-8',
|
'Content-Type': 'text/plain;charset=UTF-8',
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
post_url, None, note, data=json.dumps(form).encode(),
|
post_url, None, note, data=json.dumps(form).encode(),
|
||||||
headers=headers, expected_status=400)
|
headers=headers, expected_status=400)
|
||||||
error = dict_get(response, ('error', 'error_description', 'error_code'))
|
error = response.get('error_description') or response.get('error_code')
|
||||||
if error:
|
if error:
|
||||||
fail(error)
|
fail(error)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user