Giter Site home page Giter Site logo

weizhenye / ass-compiler Goto Github PK

View Code? Open in Web Editor NEW
96.0 96.0 17.0 171 KB

Parses and compiles ASS subtitle format to easy-to-use data structure

Home Page: https://ass.js.org/ass-compiler/

License: MIT License

JavaScript 100.00%
ass compiler parser ssa subtitle

ass-compiler's People

Contributors

icemic avatar notorca avatar pboymt avatar red5h4d0w avatar weizhenye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ass-compiler's Issues

Serialize back to .ass

Hi,

I really like you library but is there any way to go from the tree generated from compile or parse back into an .ass file?

Latest version breaks ASS format

I was using 0.1.4 version and it was producing correct format subtitle file e.g.

[Script Info]
ScriptType: v4.00+
Collisions: Normal
Timer: 100.0000
PlayResX: 100
PlayResY: 100

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Noto,10,red,blue,green,grey,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,0

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0000,0000,0000,,This is a test of the ASS format and some basic features in it.
Dialogue: 0,0:00:05.00,0:00:07.00,Default,,0000,0000,0000,,This and the previous line should both show at the bottom of the video in 20 pixel high white Arial with a 2 pixel black outline and 2 pixel offset shadow. This line is long so it should automatically be broken into several lines that are approximately even length, with upper lines being longer.

I've upgraded to 0.1.7 and it started producing additional events columns which are not even in the specifications of ASS format nor supported by for example ffmpeg

[Script Info]
ScriptType: v4.00+
Collisions: Normal
Timer: 100.0000
PlayResX: 100
PlayResY: 100

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Noto,10,red,blue,green,grey,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,0

[Events]
Format: Marked, Layer, Start, End, Text, Text.parsed, Text.parsed[0].tags, Text.parsed[0].text, Text.parsed[0].drawing, Style, Name, MarginL, MarginR, MarginV, Effect
Dialogue: Marked=0,0,0:00:00.00,0:00:05.00,This is a test of the ASS format and some basic features in it.,,,,,Default,,0000,0000,0000,
Dialogue: Marked=0,0,0:00:05.00,0:00:07.00,This and the previous line should both show at the bottom of the video in 20 pixel high white Arial with a 2 pixel black outline and 2 pixel offset shadow. This line is long so it should automatically be broken into several lines that are approximately even length, with upper lines being longer.,,,,,Default,,0000,0000,0000,

Code to recreate the issue:

  const ssa = new SSA()
  const subs = [{
    startTime: 0.000,
    endTime: 5.000,
    content: 'This is a test of the ASS format and some basic features in it.'
  }, {
    startTime: 5.000,
    endTime: 7.000,
    content: 'This and the previous line should both show at the bottom of the video in 20 pixel high white Arial with a 2 pixel black outline and 2 pixel offset shadow. This line is long so it should automatically be broken into several lines that are approximately even length, with upper lines being longer.'
  }]
  
  const subtitleSettings = {
    Fontname: 'Comic',
    FontsizeBase: 10,
    MarginBase: 10,
    UBase: 1,
    PrimaryColour: 'red',
    SecondaryColour: 'blue',
    BackColour: 'grey',
    OutlineColour: 'green',
    BorderStyle: 1,
    Outline: 2,
    Shadow: 2,
    Width: 100,
    Height: 100,
  }
  const result = ssa.toString(subs, subtitleSettings)

`t` tag is defined in different ways in decompileTag, stringifyTag, and typescript type definitions

In typescript types t contains field tags defined as array of tags

tags: { [K in keyof ParsedTag]: ParsedTag[K]; }[];

That is in sync with stringifyTag usage
https://github.com/weizhenye/ass-compiler/blob/master/src/stringifier.js#L51
but decompileTag expects field named tag containing single tag
https://github.com/weizhenye/ass-compiler/blob/master/src/decompiler.js#L55

Long integer colors

Greetings!

First of all, thank you for your ASS libraries!

I have found a minor error; Colors should, according to spec, be able to be specified as long integers (I'm guessing long here means "at least 32-bit", like in C).

Spec states:

A long integer BGR (blue-green-red) value. ie. the byte order in the hexadecimal equivelent of this number is BBGGRR

...

The color format contains the alpha channel, too. (AABBGGRR)

The integer should be considered a signed integer, as seen in the test file:

[Script Info]
; Comment 1
; Comment 2
Title: SSA test
Original Script: asticode
Script Updated By: version 2.8.01
ScriptType: v4.00
Collisions: Normal
PlayResY: 600
PlayDepth: 0
Timer: 100,0000

[Unknown]
Unknown

[V4 Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: 1,f1,20,65535,65535,65535,-2147483640,-1,0,7,1,4,7,1,4,7,0.1,0
Style: 2,f2,20,15724527,65535,65535,986895,-1,0,8,2,5,8,2,5,8,0.2,1
Style: 3,f3,20,&H00B4FCFC,&H00B4FCFC,&H00000008,&H00000008,0,0,9,3,6,9,3,6,9,0.3,2

[Events]
Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: Marked=0,0:00:01.00,0:00:01.99,1,Cher,0000,0000,0000,test,{\pos(400,570)}(deep rumbling)
Dialogue: Marked=1,0:00:02.00,0:00:03.04,1,Cher,0000,0000,0000,test,{\pos(400,570)}(deep rumbling)
Dialogue: Marked=1,0:00:03.16,0:00:04.20,3,autre,0000,0000,0000,,This place is horrible.
Dialogue: Marked=1,0:00:04.24,0:00:05.28,1,autre,0000,0000,0000,,Smells like balls.
Dialogue: Marked=1,0:00:05.32,0:00:06.36,2,autre,0000,0000,0000,,We don't belong\nin this shithole.
Dialogue: Marked=1,0:00:06.40,0:00:07.44,3,autre,0000,0000,0000,,(computer playing\nelectronic melody)

You can see the error using your fantastic online viewer ๐Ÿ‘

Parsing non-standard event effects

I would like if the parser could somehow parse the Effect Portion of an event as a string and expose it in the parsed object.
For instance, it would be useful in determining what lines represent karaoke lines in the following example.

...
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Comment: 0,0:00:00.00,0:00:00.00,Sample KM [Up],,0,0,0,template pre-line all keeptags,!retime("line",$start < 900 and -$start or -900,200)!{!$start < 900 and "\\k" .. ($start/10) or "\\k90"!\fad(!$start < 900 and $start or 300!,200)}
Comment: 0,0:00:00.68,0:00:06.31,Sample KM [Up],,0,0,0,karaoke,{\k26}o{\k33}wa{\k71}ri {\k37}wo {\k39}ma{\k75}tsu {\k34}se{\k38}tsu{\k36}na {\k36}ni {\k40}ki{\k39}mi {\k59}wa
...

I understand that Effect can only EffectBanner or EffectScroll and that this utilisation is not part of v4.00+ ASS specifications, but the KaraTemplater from Aegisub ignores that all the time and uses the Effect property to store fx, template, karaoke and such instructions. This is why I think it could be useful

Some additional parsing errors for these `ass` subtitles

Thank your the fix in #9! I have identified three more with problematic subtitles on 0.1.5. These errors are in the online viewer:

TypeError: Cannot read properties of undefined (reading 'parsed')
    at compileDialogues (ass-compiler.js:813:26)
    at Object.compile (ass-compiler.js:972:18)
    at run ((index):132:32)
    at codemirror.js:2076:45
    at codemirror.js:2033:24
    at codemirror.js:2047:11
    at jn (codemirror.js:3787:15)
    at codemirror.js:3924:17
    at a (codemirror.js:6495:11)
    at n.onload (codemirror.js:6521:11)

And:

TypeError: Cannot read properties of null (reading '1')
    at parseTag (ass-compiler.js:79:22)
    at Array.map (<anonymous>)
    at parseTags (ass-compiler.js:174:17)
    at parseText (ass-compiler.js:184:18)
    at parseDialogue (ass-compiler.js:231:22)
    at parse (ass-compiler.js:313:49)
    at Object.compile (ass-compiler.js:960:16)
    at run ((index):132:32)
    at codemirror.js:2076:45
    at codemirror.js:2033:24

The problematic subs are from 3 different series/groups: subs.zip

Thank you for all your amazing work on this library ๐Ÿ‘

[BUG] Style decompiler is case sensitive

I encountered the following .ass style header in production:

Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,Strikeout,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding

The Strikeout property in this style header is not written as StrikeOut.
When using ass-compiler to decompile this, StrikeOut will be undefined.
And when serializing again, StrikeOut is undefined, making the .ass invalid.

The parsing of headers should be using case-insensitive comparisons.
I'd be happy to e-mail you the .ass file if that helps.

TypeError: Cannot read property '1' of null

I encountered the following error parsing an .ass file with 0.1.4:

TypeError: Cannot read properties of null (reading '1')
    at parseTag (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:84:24)
    at Array.map (<anonymous>)
    at parseTags (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:174:17)
    at parseText (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:184:18)
    at parseDialogue (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:231:22)
    at Object.parse (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:313:49)
    at run (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\dist\functions\parseAsync.js:26:26)
    at Object.parseAsync (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\dist\functions\parseAsync.js:9:22)
    at async Object.extractAsync (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\dist\functions\extractAsync.js:12:16)
    at async traceAsync (C:\Users\Deathspike\OneDrive\Data\Sources\normalize-ssa\dist\actions\parseAsync.js:55:24)

This occurred in the following ass subtitle:

The World God Only Knows - S02E09.eng.zip

Let me know if I can provide more info ๐Ÿ‘

TypeError: Cannot read property '1' of null

I encountered the following error parsing an .ass file:

(node:19260) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
    at parseTag (C:\Users\Deathspike\AppData\Roaming\npm\node_modules\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:79:22)
    at Array.map (<anonymous>)
    at parseTags (C:\Users\Deathspike\AppData\Roaming\npm\node_modules\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:172:17)
    at parseText (C:\Users\Deathspike\AppData\Roaming\npm\node_modules\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:182:18)
    at parseDialogue (C:\Users\Deathspike\AppData\Roaming\npm\node_modules\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:229:22)
    at Object.parse (C:\Users\Deathspike\AppData\Roaming\npm\node_modules\normalize-ssa\node_modules\ass-compiler\dist\ass-compiler.js:315:49)
    at Object.parseSubAsync (C:\Users\Deathspike\AppData\Roaming\npm\node_modules\normalize-ssa\dist\parsers\parseSub.js:27:26)

This occurred on the following line in the .ass:

Comment: 0,0:02:26.00,0:02:28.12,Sign,,0,0,0,,{Cell phone display}{Top line, near battery:}No signal{Third line, after "To":}Kojou-kun{Yellow popup title:}There was an error while attempting to send.{Yellow popup body:}There was an error while attempting to send your photo. There is a problem with the server or network, or your device may have been left idling for too long.

And here's the file:

badsub.zip

I hope you can fix this one. Thank you for the awesome library!

Incorrect types?

Hello :)

I'm trying to update to version 0.1.0.

However, it looks like the online viewer and the types are not the same.

If I want to parse dialogues in an ASS files I should be able to from the dialogues object from the main object I get from parse. However, the types seem to still wait a events and dialogue objects inside...

Am I doing something wrong or are types not up-to-date ?

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.