|
|
@ -2757,6 +2757,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|
|
|
|
|
|
|
|
|
|
|
begin_index = 0
|
|
|
|
begin_index = 0
|
|
|
|
download_start_time = ctx.get('start') or time.time()
|
|
|
|
download_start_time = ctx.get('start') or time.time()
|
|
|
|
|
|
|
|
section_start = ctx.get('section_start') or 0
|
|
|
|
|
|
|
|
section_end = ctx.get('section_end') or math.inf
|
|
|
|
|
|
|
|
|
|
|
|
lack_early_segments = download_start_time - (live_start_time or download_start_time) > MAX_DURATION
|
|
|
|
lack_early_segments = download_start_time - (live_start_time or download_start_time) > MAX_DURATION
|
|
|
|
if lack_early_segments:
|
|
|
|
if lack_early_segments:
|
|
|
@ -2797,8 +2799,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|
|
|
fragment_base_url = fmt_info['fragment_base_url']
|
|
|
|
fragment_base_url = fmt_info['fragment_base_url']
|
|
|
|
assert fragment_base_url
|
|
|
|
assert fragment_base_url
|
|
|
|
|
|
|
|
|
|
|
|
_last_seq = int(re.search(r'(?:/|^)sq/(\d+)', fragments[-1]['path']).group(1))
|
|
|
|
return True
|
|
|
|
return True, _last_seq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.write_debug(f'[{video_id}] Generating fragments for format {format_id}')
|
|
|
|
self.write_debug(f'[{video_id}] Generating fragments for format {format_id}')
|
|
|
|
while is_live:
|
|
|
|
while is_live:
|
|
|
@ -2818,11 +2819,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|
|
|
last_segment_url = None
|
|
|
|
last_segment_url = None
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
should_continue, last_seq = _extract_sequence_from_mpd(True, no_fragment_score > 15)
|
|
|
|
should_continue = _extract_sequence_from_mpd(True, no_fragment_score > 15)
|
|
|
|
no_fragment_score += 2
|
|
|
|
no_fragment_score += 2
|
|
|
|
if not should_continue:
|
|
|
|
if not should_continue:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_fragment = fragments[-1]
|
|
|
|
|
|
|
|
last_seq = int(re.search(r'(?:/|^)sq/(\d+)', last_fragment['path']).group(1))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
known_fragment = next(
|
|
|
|
|
|
|
|
(fragment for fragment in fragments if f'sq/{known_idx}' in fragment['path']), None)
|
|
|
|
|
|
|
|
if known_fragment and known_fragment['end'] > section_end:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if known_idx > last_seq:
|
|
|
|
if known_idx > last_seq:
|
|
|
|
last_segment_url = None
|
|
|
|
last_segment_url = None
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -2832,20 +2841,31 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|
|
|
if begin_index < 0 and known_idx < 0:
|
|
|
|
if begin_index < 0 and known_idx < 0:
|
|
|
|
# skip from the start when it's negative value
|
|
|
|
# skip from the start when it's negative value
|
|
|
|
known_idx = last_seq + begin_index
|
|
|
|
known_idx = last_seq + begin_index
|
|
|
|
|
|
|
|
|
|
|
|
if lack_early_segments:
|
|
|
|
if lack_early_segments:
|
|
|
|
known_idx = max(known_idx, last_seq - int(MAX_DURATION // fragments[-1]['duration']))
|
|
|
|
known_idx = max(known_idx, last_seq - int(MAX_DURATION // last_fragment['duration']))
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
for idx in range(known_idx, last_seq):
|
|
|
|
for idx in range(known_idx, last_seq):
|
|
|
|
# do not update sequence here or you'll get skipped some part of it
|
|
|
|
# do not update sequence here or you'll get skipped some part of it
|
|
|
|
should_continue, _ = _extract_sequence_from_mpd(False, False)
|
|
|
|
should_continue = _extract_sequence_from_mpd(False, False)
|
|
|
|
if not should_continue:
|
|
|
|
if not should_continue:
|
|
|
|
known_idx = idx - 1
|
|
|
|
known_idx = idx - 1
|
|
|
|
raise ExtractorError('breaking out of outer loop')
|
|
|
|
raise ExtractorError('breaking out of outer loop')
|
|
|
|
|
|
|
|
|
|
|
|
last_segment_url = urljoin(fragment_base_url, 'sq/%d' % idx)
|
|
|
|
last_segment_url = urljoin(fragment_base_url, 'sq/%d' % idx)
|
|
|
|
yield {
|
|
|
|
frag_duration = last_fragment['duration']
|
|
|
|
'url': last_segment_url,
|
|
|
|
frag_start = last_fragment['start'] - (last_seq - idx) * frag_duration
|
|
|
|
'fragment_count': last_seq,
|
|
|
|
frag_end = frag_start + frag_duration
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if frag_start >= section_start and frag_end <= section_end:
|
|
|
|
|
|
|
|
yield {
|
|
|
|
|
|
|
|
'url': last_segment_url,
|
|
|
|
|
|
|
|
'duration': frag_duration,
|
|
|
|
|
|
|
|
'start': frag_start,
|
|
|
|
|
|
|
|
'end': frag_end,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if known_idx == last_seq:
|
|
|
|
if known_idx == last_seq:
|
|
|
|
no_fragment_score += 5
|
|
|
|
no_fragment_score += 5
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|