weizhenye / ass-compiler Goto Github PK
View Code? Open in Web Editor NEWParses and compiles ASS subtitle format to easy-to-use data structure
Home Page: https://ass.js.org/ass-compiler/
License: MIT License
Parses and compiles ASS subtitle format to easy-to-use data structure
Home Page: https://ass.js.org/ass-compiler/
License: MIT License
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?
Hi,
I'm getting a similar error message to #6, but I'm already using 0.1.2.
Here is the subtitle file that's causing problems:
Beastars S02E09.zip
Thanks very much for this excellent library, it's really helping me out with my subtitle-indexer project!
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)
In typescript types t
contains field tags
defined as array of tags
Line 56 in 200363a
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
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 ๐
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
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 ๐
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.
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 ๐
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:
I hope you can fix this one. Thank you for the awesome library!
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.