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

TTML to VTT style migration #48

Conversation

Avishek-Gulshan
Copy link

  • 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
@coveralls
Copy link

coveralls commented Jul 9, 2021

Coverage Status

Coverage decreased (-3.2%) to 73.198% when pulling b86cb77 on EurosportDigital:TTML_TO_VTT_STYLE_MIGRATION into 8c108a5 on asticode:master.

@Avishek-Gulshan
Copy link
Author

Hi,

Can you please have a look at this PR. See if this makes sense

@Avishek-Gulshan
Copy link
Author

Hi, Please take a look at this PR

@asticode
Copy link
Owner

This is a big PR and I'm pretty busy right now, I'll need some time to review it

Copy link
Owner

@asticode asticode left a 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
Copy link
Owner

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"`
Copy link
Owner

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 := ""
Copy link
Owner

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 := ""
Copy link
Owner

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{}) {
Copy link
Owner

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 {
Copy link
Owner

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) {
Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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

@NhanNguyen700
Copy link
Contributor

This one looks interesting, any further work?

@asticode
Copy link
Owner

asticode commented Nov 9, 2023

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 👍

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.

None yet

5 participants