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

[WIP] Add basic writers for going from List<SubtitleItem> --> Stream #31

Merged
merged 4 commits into from
Jul 7, 2021

Conversation

GrumpyBear57
Copy link
Contributor

#25 mentioned you'd be open to a PR for adding writers, and since I'm writing some for our project anyways, I decided to submit it upstream for others to use.

Currently I've implemented the SSA writer with both sync and async methods. I moved the consts from SsaParser.cs into a new util class (SsaFormatConstants.cs) so that I didn't have to have duplicates in the writer. I'm writing to a stream since our usecase requires that over a file (since it's serving over the network), but it shouldn't be to difficult to either create methods that do write to a file, or just have the user write the stream to the file themselves.

I'm only familiar with (and our service only requires) SSA and SRT writers, so it's likely that's all I'll add support for.

I'll get the SRT writer finished up asap so this can actually be merged, but let me know if you have any concerns, or need me to change anything. If you're interested, I may also submit another PR with some more additions, like the option to strip out formatting codes from SSA (again, I'll be doing this anyways since we require it, might as well upstream it if you want it).

@GrumpyBear57
Copy link
Contributor Author

I'm finished with writing the writers (hah) for now, so this should be good to merge. I may come back and add some of the other formats at some point if we decide we need them, but I don't really foresee that happening for anything except for maybe WebVTT.

Something I noticed was that multiline SSA/ASS dialogue doesn't get split into multiple items in the SubtitleItem.Lines list, but there's a TODO on line 96 of SsaParser.cs to do this, which I figure I could pretty quickly do. Also, as I said, I'm planning on adding some sort of formatting/styling stripping, so I could do both of these at the same time if you want, either in a new PR, or this one, or individually. Up to you what you want to do, or if you want them or not.

@GrumpyBear57 GrumpyBear57 marked this pull request as ready for review July 6, 2021 22:52
@AlexPoint
Copy link
Owner

Good job with the writers!
I don't have the time to test those two writers subtitles extensively but everything seems to work fine.
Feel free to add the WebVTT writer if you ever need it; I will merge the pull request then.

@AlexPoint AlexPoint closed this Jul 7, 2021
@AlexPoint AlexPoint reopened this Jul 7, 2021
@AlexPoint AlexPoint merged commit 1e36d61 into AlexPoint:master Jul 7, 2021
@GrumpyBear57 GrumpyBear57 deleted the sub-writing branch July 9, 2021 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants