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

Update srtfile.py #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions pysrt/srtfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,22 @@ def write_into(self, output_file, eol=None):
# which already contain a trailing eol though.
if not string_repr.endswith(2 * output_eol):
output_file.write(output_eol)

def export(self, eol = None):
"""Exports returns the contents of srt as str"""
output_eol = eol or self.eol
output_text = ''

for item in self:
string_repr = str(item)
if output_eol != '\n':
string_repr = string_repr.replace('\n', output_eol)
output_text += string_repr
if not string_repr.endswith(2 * output_eol):
output_text += output_eol

return output_text

@classmethod
def _guess_eol(cls, string_iterable):
first_line = cls._get_first_line(string_iterable)
Expand Down