Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add style support for write (VTT only) #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions webvtt/webvtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WebVTT(object):
def __init__(self, file='', captions=None, styles=None):
self.file = file
self._captions = captions or []
self._styles = styles
self._styles = styles or []

def __len__(self):
return len(self._captions)
Expand Down Expand Up @@ -105,7 +105,7 @@ def save_as_srt(self, output=''):

def write(self, f, format='vtt'):
if format == 'vtt':
WebVTTWriter().write(self._captions, f)
WebVTTWriter().write(self._styles, self._captions, f)
elif format == 'srt':
SRTWriter().write(self._captions, f)
# elif output_format == OutputFormat.SBV:
Expand Down
10 changes: 7 additions & 3 deletions webvtt/writers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@

class WebVTTWriter(object):

def write(self, captions, f):
f.write(self.webvtt_content(captions))
def write(self, styles, captions, f):
f.write(self.webvtt_content(styles, captions))

def webvtt_content(self, captions):
def webvtt_content(self, styles, captions):
"""
Return captions content with webvtt formatting.
"""
output = ["WEBVTT"]
for style in styles:
output.append("")
output.append("STYLE")
output.append(style.text)
for caption in captions:
output.append("")
if caption.identifier:
Expand Down