From 91eecd994438719927c1ed5a03c617f70d9343dd Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 13 Dec 2023 18:12:52 -0500 Subject: [PATCH] Chore: minor update --- Contents/Code/__init__.py | 27 ++++++++++++++++++--------- Contents/Code/constants.py | 16 +++++++++++----- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 91bc7ea..f440a50 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -330,15 +330,24 @@ def update(self, metadata, media, lang, force=False): # 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] and len(durations) == 1 \ - and durations[0] > chapter_min_duration: - 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 + 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 diff --git a/Contents/Code/constants.py b/Contents/Code/constants.py index 1f351fd..2dd6482 100644 --- a/Contents/Code/constants.py +++ b/Contents/Code/constants.py @@ -45,11 +45,17 @@ ] # File Extensions -VIDEO_EXTENSIONS = ('.mp4', '.m4v', '.mkv', '.wmv', '.avi', - '.flv', '.mov', '.3gp', '.rm', '.rmvb', - '.ts', '.m2ts', '.mpegts', '.mpeg') -SUBTITLE_EXTENSIONS = ('.srt', '.ass', '.ssa', '.smi', - '.sub', '.idx', '.vtt', '.psb') +SUBTITLE_EXTENSIONS = ('.utf', '.utf8', '.utf-8', '.srt', '.smi', + '.rt', '.ssa', '.aqt', '.jss', '.ass', + '.idx', '.sub', '.txt', '.psb', '.vtt') +VIDEO_EXTENSIONS = ('.3g2', '.3gp', '.asf', '.asx', '.avc', '.avi', + '.avs', '.bivx', '.bup', '.divx', '.dv', '.dvr-ms', + '.evo', '.fli', '.flv', '.m2t', '.m2ts', '.m2v', + '.m4v', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', + '.mts', '.nsv', '.nuv', '.ogm', '.ogv', '.tp', + '.pva', '.qt', '.rm', '.rmvb', '.sdp', '.svq3', + '.strm', '.ts', '.ty', '.vdr', '.viv', '.vob', + '.vp3', '.wmv', '.wpl', '.wtv', '.xsp', '.xvid', '.webm') # Preference Keys KEY_API_SERVER = 'api_server'