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

fix(WebVTT): Add support to voice tag styles #4845

Merged
merged 5 commits into from
Jan 19, 2023

Conversation

avelad
Copy link
Member

@avelad avelad commented Dec 16, 2022

closes #4844
fixes #4843
fixes #4479

BEGIN_COMMIT_OVERRIDE
fix(WebVTT): Fix voice tag styles
END_COMMIT_OVERRIDE

@avelad avelad added type: enhancement New feature or request priority: P2 Smaller impact or easy workaround component: WebVTT The issue involves WebVTT subtitles specifically labels Dec 16, 2022
@avelad avelad added this to the v4.4 milestone Dec 16, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2022

Incremental code coverage: 91.26%

for (let i = 0; i < payload.length; i++) {
if (payload[i] === '/') {
const end = payload.indexOf('>', i);
if (end <= i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what condition do we expect end <= i? We start searching at i, so end will only be less than i if it's -1. And we know that payload[i] is equal to '/', so end is guaranteed to not equal i.

If this is just meant to handle end being -1, then it'd be more informative to write that out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll change it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

* @return {string} processed payload
* @private
*/
static replaceVoiceStylePayload_(payload) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this method is correct?
I tried running it on this simple content:

'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'<v A>Test\n\n' +
'00:00:40.000 --> 00:00:50.000\n' +
'<v B>Test'

And I got this output (broken into multiple lines for readability):

'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'<v.voice-A>Test\n\n' +
'00:00:40.000 --> 00:00:50.000\n' +
'<v.voice-B>Test\n' +
'</v.voice-A></v.voice-B>'

Note that both of the end tags are at the end of the file. Also, the end tags are in the wrong order; this ends up being like <A><B></A></B>, which is incorrectly nested.

Incidentally, if one of the tags already has an end tag, the other isn't given one:

'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'<v A>Test</v>\n\n' +
'00:00:40.000 --> 00:00:50.000\n' +
'<v B>Test'

Results in:

'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'<v.voice-A>Test</v.voice-A>\n\n' +
'00:00:40.000 --> 00:00:50.000\n' +
'<v.voice-B>Test\n'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are wrong! The payload parameter is <v A>Test</v> or <v B>Test. I retested with this input and it works well!

Copy link
Contributor

@theodab theodab Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, I had misread the method. I was mistakenly thinking it was parseCueStyles as in parse the styles of all cues, not parse all of the styles of one cue.
I guess if the expectation is that there will be at most one voice tag per invocation of this method, this should be fine.

lib/text/vtt_text_parser.js Show resolved Hide resolved
@avelad avelad requested a review from theodab January 11, 2023 16:06
@avelad
Copy link
Member Author

avelad commented Jan 18, 2023

@theodab can you review again? Thanks!

@avelad avelad merged commit a5f8b43 into shaka-project:main Jan 19, 2023
@avelad
Copy link
Member Author

avelad commented Jan 19, 2023

Thanks @theodab !!

@avelad avelad deleted the voice-webvtt branch January 19, 2023 12:34
@joeyparrish
Copy link
Member

Good news: This fixed one of the test cases I'm adding for VTT layout. 😁

@avelad avelad restored the voice-webvtt branch January 19, 2023 19:30
@avelad avelad deleted the voice-webvtt branch January 19, 2023 19:31
@joeyparrish joeyparrish changed the title feat(WebVTT): Add support to voice tag styles fix(WebVTT): Add support to voice tag styles Jan 30, 2023
joeyparrish pushed a commit that referenced this pull request Jan 30, 2023
joeyparrish pushed a commit that referenced this pull request Jan 30, 2023
joeyparrish pushed a commit that referenced this pull request Jan 30, 2023
joeyparrish pushed a commit that referenced this pull request Jan 30, 2023
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: WebVTT The issue involves WebVTT subtitles specifically priority: P2 Smaller impact or easy workaround status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
3 participants