Skip to content

Commit

Permalink
Fix: deprecate chapters (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Dec 14, 2023
1 parent 91eecd9 commit 476600e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
50 changes: 25 additions & 25 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,31 +323,31 @@ def update(self, metadata, media, lang, force=False):
if m.runtime:
metadata.duration = m.runtime * 60 * 1000 # millisecond

# Chapters
metadata.chapters.clear()
chapter_min_duration = 10 * 60 * 1000 # 10 minutes
chapter_gen_interval = 5 * 60 * 1000 # 5 minutes
# only generate chapters for media with single file
durations = [int(p.duration) for p in utils.extra_media_parts(media)
if int(p.duration) > 0]
if Prefs[KEY_ENABLE_CHAPTERS]:
if not durations:
Log.Warn('Chapter: no valid duration for media: {id}'
.format(id=metadata.id))
elif len(durations) > 1:
Log.Warn('Chapter: ignore multi-part media: {id}'
.format(id=metadata.id))
elif durations[0] < chapter_min_duration:
Log.Warn('Chapter: ignore short-duration media: {id}'
.format(id=metadata.id))
else:
duration = durations[0]
for i, offset in enumerate(range(0, duration, chapter_gen_interval)):
start, end = offset, offset + chapter_gen_interval
chapter = metadata.chapters.new()
chapter.title = 'Chapter {i}'.format(i=(i + 1))
chapter.start_time_offset = start
chapter.end_time_offset = end if end < duration else duration
# # Chapters
# metadata.chapters.clear()
# chapter_min_duration = 10 * 60 * 1000 # 10 minutes
# chapter_gen_interval = 5 * 60 * 1000 # 5 minutes
# # only generate chapters for media with single file
# durations = [int(p.duration) for p in utils.extra_media_parts(media)
# if int(p.duration) > 0]
# if Prefs[KEY_ENABLE_CHAPTERS]:
# if not durations:
# Log.Warn('Chapter: no valid duration for media: {id}'
# .format(id=metadata.id))
# elif len(durations) > 1:
# Log.Warn('Chapter: ignore multi-part media: {id}'
# .format(id=metadata.id))
# elif durations[0] < chapter_min_duration:
# Log.Warn('Chapter: ignore short-duration media: {id}'
# .format(id=metadata.id))
# else:
# duration = durations[0]
# for i, offset in enumerate(range(0, duration, chapter_gen_interval)):
# start, end = offset, offset + chapter_gen_interval
# chapter = metadata.chapters.new()
# chapter.title = 'Chapter {i}'.format(i=(i + 1))
# chapter.start_time_offset = start
# chapter.end_time_offset = end if end < duration else duration

# Clear Ratings
metadata.rating = 0.0
Expand Down
1 change: 0 additions & 1 deletion Contents/Code/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
KEY_API_SERVER = 'api_server'
KEY_API_TOKEN = 'api_token'
KEY_ENABLE_COLLECTIONS = 'enable_collections'
KEY_ENABLE_CHAPTERS = 'enable_chapters'
KEY_ENABLE_DIRECTORS = 'enable_directors'
KEY_ENABLE_RATINGS = 'enable_ratings'
KEY_ENABLE_REVIEWS = 'enable_reviews'
Expand Down

0 comments on commit 476600e

Please sign in to comment.