Skip to content

Commit

Permalink
Feature: add chapters support (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Dec 12, 2023
1 parent 1ffa578 commit 15477e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def get_media_files(obj):

# Reviews
metadata.reviews.clear()

# if None:
# r = metadata.reviews.new()
# r.author = review.get('critic')
Expand All @@ -315,6 +316,26 @@ def get_media_files(obj):
# r.link = review.get('link')
# r.text = review.text

def get_media_durations(obj):
if hasattr(obj, 'all_parts'):
return [int(part.duration) for part in obj.all_parts() if hasattr(part, 'duration')]

# Chapters
metadata.chapters.clear()
# only generate chapters if is a single video file
durations = get_media_durations(media)
if Prefs[KEY_ENABLE_CHAPTERS] and len(durations) == 1 \
and durations[0] > 10 * 60 * 1000:
duration = durations[0]
interval = 5 * 60 * 1000 # every 5 minutes
for i, offset in enumerate(range(0, duration, interval)):
start, end = offset, offset + 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)

# Director
metadata.directors.clear()
if Prefs[KEY_ENABLE_DIRECTORS] and m.director:
Expand Down
1 change: 1 addition & 0 deletions Contents/Code/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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_TRAILERS = 'enable_trailers'
Expand Down
6 changes: 6 additions & 0 deletions Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"type": "bool",
"default": "false"
},
{
"id": "enable_chapters",
"label": "Enable chapters",
"type": "bool",
"default": "true"
},
{
"id": "enable_directors",
"label": "Enable directors",
Expand Down

0 comments on commit 15477e3

Please sign in to comment.