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
TTML to VTT style migration #48
TTML to VTT style migration #48
Conversation
Avishek-Gulshan
commented
Jul 9, 2021
- Update TTM L parser to push parent style to child tags
- Creating new custom style classes by combining inline style and style class
- Added additional style propagation from TTML to VTT
- Added style migration from TTML to WEBVTT
- Added support for STYLE classes
- Pushing parent style and inline style to child <span> - Creating new custom style class after combing inline style and style class as multiple format doesn't support inline style + style
Hi, Can you please have a look at this PR. See if this makes sense |
Hi, Please take a look at this PR |
This is a big PR and I'm pretty busy right now, I'll need some time to review it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a huge PR, I've not reviewed everything but let start from here.
You need to fix tests as well.
WebVTTVertical string | ||
WebVTTViewportAnchor string | ||
WebVTTWidth string | ||
WebVTTBackgroundColor string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you order new fields alphabetically?
@@ -196,7 +213,7 @@ func (i *TTMLInItems) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err | |||
// TTMLInItem represents an input TTML item | |||
type TTMLInItem struct { | |||
Style string `xml:"style,attr,omitempty"` | |||
Text string `xml:",chardata"` | |||
Text string `xml:",innerxml"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this tag, what difference does it make ?
@@ -326,34 +343,53 @@ func ReadFromTTML(i io.Reader) (o *Subtitles, err error) { | |||
s.Style = o.Styles[id] | |||
} | |||
|
|||
//take care of body style | |||
defaultBodyStyle := "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename this variable to bodyStyle
?
@@ -326,34 +343,53 @@ func ReadFromTTML(i io.Reader) (o *Subtitles, err error) { | |||
s.Style = o.Styles[id] | |||
} | |||
|
|||
//take care of body style | |||
defaultBodyStyle := "" | |||
defaultRegion := "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename this variable to bodyRegion
?
defaultRegion = ttml.Body.Region | ||
} | ||
//if true create a new default body style and push it in o.Styles | ||
if ttml.Body.TTMLInStyleAttributes != (TTMLInStyleAttributes{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather make ttml.Body.TTMLInStyleAttributes
a pointer in the struct so that it checks != nil
here
} | ||
|
||
//combineInlineStyles combines two StyleAttributes keeping everything from destination and adding missing data from source to destination | ||
func combineInlineStyles(source *StyleAttributes, destination StyleAttributes) *StyleAttributes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather make this a func (s *StyleAttributes) merge(in *StyleAttributes) (out *StyleAttributes)
and move it to subtitles.go
return | ||
} | ||
|
||
func checkIfCustomStyleExists(styleMap map[Style]string, style *Style) (bool, string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you transform this to func (ss ttmlCustomStyles) exists(s *Style) (id string, ok bool)
instead ?
newStyle.Style = lineItem.Style.Style | ||
} | ||
newStyle.InlineStyle.propagateTTMLAttributes() | ||
ok, id := checkIfCustomStyleExists(customStyleMap, newStyle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this a one liner : if ok, id := checkIfCustomStyleExists(customStyleMap, newStyle); ok {
|
||
//Pushing Inline style from parent tag to every child tag then combining it with child tag's Style to create a new style and then assigning that style to the child tag. | ||
customStyleNumber := 1 | ||
var customStyleMap = make(map[Style]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it should be the other way around and with a pointer var customStyleMap = make(map[string]*Style)
, and you should rename this variables to customStyles
|
||
//Pushing Inline style from parent tag to every child tag then combining it with child tag's Style to create a new style and then assigning that style to the child tag. | ||
customStyleNumber := 1 | ||
var customStyleMap = make(map[Style]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather you create a specific type for this called type ttmlCustomStyles map[string]*Style
1a6c252
to
012fd3a
Compare
This one looks interesting, any further work? |
Requested changes need to be addressed (this was the first part of my review) but based on the fact that this PR is pretty old, I doubt the OP will ever do it. If you feel like it, you can pick it up 👍 |