0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-25 02:45:12 +00:00

[ModifyChapters] Do not mutate original chapters (#1322)

Closes #1295 
Authored by: nihil-admirari
This commit is contained in:
Nil Admirari 2021-10-19 08:51:05 +00:00 committed by GitHub
parent 1e520b5535
commit e619d8a752
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,8 +31,10 @@ def __init__(self, downloader, remove_chapters_patterns=None, remove_sponsor_seg
@PostProcessor._restrict_to(images=False)
def run(self, info):
# Chapters must be preserved intact when downloading multiple formats of the same video.
chapters, sponsor_chapters = self._mark_chapters_to_remove(
info.get('chapters') or [], info.get('sponsorblock_chapters') or [])
copy.deepcopy(info.get('chapters')) or [],
copy.deepcopy(info.get('sponsorblock_chapters')) or [])
if not chapters and not sponsor_chapters:
return [], info
@ -126,7 +128,7 @@ def _remove_marked_arrange_sponsors(self, chapters):
cuts = []
def append_cut(c):
assert 'remove' in c
assert 'remove' in c, 'Not a cut is appended to cuts'
last_to_cut = cuts[-1] if cuts else None
if last_to_cut and last_to_cut['end_time'] >= c['start_time']:
last_to_cut['end_time'] = max(last_to_cut['end_time'], c['end_time'])
@ -154,7 +156,7 @@ def excess_duration(c):
new_chapters = []
def append_chapter(c):
assert 'remove' not in c
assert 'remove' not in c, 'Cut is appended to chapters'
length = c['end_time'] - c['start_time'] - excess_duration(c)
# Chapter is completely covered by cuts or sponsors.
if length <= 0:
@ -237,7 +239,7 @@ def append_chapter(c):
heapq.heappush(chapters, (c['start_time'], i, c))
# (normal, sponsor) and (sponsor, sponsor)
else:
assert '_categories' in c
assert '_categories' in c, 'Normal chapters overlap'
cur_chapter['_was_cut'] = True
c['_was_cut'] = True
# Push the part after the sponsor to PQ.