mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 21:45:02 +03:00
[youtube] fix download for non-DASH streams
This commit is contained in:
parent
b1a452d762
commit
358d797781
@ -218,7 +218,10 @@ class YouTube(VideoExtractor):
|
|||||||
ytplayer_config = json.loads(re.search('ytplayer.config\s*=\s*([^\n]+?});', video_page).group(1))
|
ytplayer_config = json.loads(re.search('ytplayer.config\s*=\s*([^\n]+?});', video_page).group(1))
|
||||||
self.html5player = 'https://www.youtube.com' + ytplayer_config['assets']['js']
|
self.html5player = 'https://www.youtube.com' + ytplayer_config['assets']['js']
|
||||||
# Workaround: get_video_info returns bad s. Why?
|
# Workaround: get_video_info returns bad s. Why?
|
||||||
stream_list = ytplayer_config['args']['url_encoded_fmt_stream_map'].split(',')
|
if 'url_encoded_fmt_stream_map' not in ytplayer_config['args']:
|
||||||
|
stream_list = json.loads(ytplayer_config['args']['player_response'])['streamingData']['formats']
|
||||||
|
else:
|
||||||
|
stream_list = ytplayer_config['args']['url_encoded_fmt_stream_map'].split(',')
|
||||||
#stream_list = ytplayer_config['args']['adaptive_fmts'].split(',')
|
#stream_list = ytplayer_config['args']['adaptive_fmts'].split(',')
|
||||||
except:
|
except:
|
||||||
if 'url_encoded_fmt_stream_map' not in video_info:
|
if 'url_encoded_fmt_stream_map' not in video_info:
|
||||||
@ -321,7 +324,7 @@ class YouTube(VideoExtractor):
|
|||||||
'container': mime_to_container(metadata['type'][0].split(';')[0]),
|
'container': mime_to_container(metadata['type'][0].split(';')[0]),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
stream_itag = stream['itag']
|
stream_itag = str(stream['itag'])
|
||||||
self.streams[stream_itag] = {
|
self.streams[stream_itag] = {
|
||||||
'itag': str(stream['itag']),
|
'itag': str(stream['itag']),
|
||||||
'url': stream['url'] if 'url' in stream else None,
|
'url': stream['url'] if 'url' in stream else None,
|
||||||
@ -367,7 +370,7 @@ class YouTube(VideoExtractor):
|
|||||||
self.caption_tracks[lang] = srt
|
self.caption_tracks[lang] = srt
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
# Prepare DASH streams
|
# Prepare DASH streams (NOTE: not every video has DASH streams!)
|
||||||
try:
|
try:
|
||||||
dashmpd = ytplayer_config['args']['dashmpd']
|
dashmpd = ytplayer_config['args']['dashmpd']
|
||||||
dash_xml = parseString(get_content(dashmpd))
|
dash_xml = parseString(get_content(dashmpd))
|
||||||
@ -451,7 +454,10 @@ class YouTube(VideoExtractor):
|
|||||||
for i in afmt.split('&')])
|
for i in afmt.split('&')])
|
||||||
for afmt in video_info['adaptive_fmts'][0].split(',')]
|
for afmt in video_info['adaptive_fmts'][0].split(',')]
|
||||||
else:
|
else:
|
||||||
streams = json.loads(video_info['player_response'][0])['streamingData']['adaptiveFormats']
|
try:
|
||||||
|
streams = json.loads(video_info['player_response'][0])['streamingData']['adaptiveFormats']
|
||||||
|
except: # no DASH stream at all
|
||||||
|
return
|
||||||
# streams without contentLength got broken urls, just remove them (#2767)
|
# streams without contentLength got broken urls, just remove them (#2767)
|
||||||
streams = [stream for stream in streams if 'contentLength' in stream]
|
streams = [stream for stream in streams if 'contentLength' in stream]
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
|
@ -37,6 +37,9 @@ class YouGetTests(unittest.TestCase):
|
|||||||
'http://www.youtube.com/attribution_link?u=/watch?v%3DldAKIzq7bvs%26feature%3Dshare', # noqa
|
'http://www.youtube.com/attribution_link?u=/watch?v%3DldAKIzq7bvs%26feature%3Dshare', # noqa
|
||||||
info_only=True
|
info_only=True
|
||||||
)
|
)
|
||||||
|
youtube.download(
|
||||||
|
'https://www.youtube.com/watch?v=Fpr4fQSh1cc', info_only=True
|
||||||
|
)
|
||||||
|
|
||||||
def test_acfun(self):
|
def test_acfun(self):
|
||||||
acfun.download('https://www.acfun.cn/v/ac11701912', info_only=True)
|
acfun.download('https://www.acfun.cn/v/ac11701912', info_only=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user