bubblesub / ass_tag_parser

A Python library for serialization and deserialization of ASS subtitle file format tags markup.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

\fs should accept float number

moi15moi opened this issue · comments

Currently, if we do parse_ass(r"{\fs146.38}example"), it will print: ass_tag_parser.errors.BadAssTagArgument: syntax error at pos 10: \fs requires an integer

\fs can handle float number, so we should not be limited to integer.

Can you provide some citation for this? The spec is badly worded but the examples include only integer fields.

In case it's illegal, the decoders will discard the decimal point treating it as a comment. This is bad because it leads to the false belief that it is supported.

In any case if this in fact is OK, then the patch is

diff --git a/README.md b/README.md
index 3c06c0e..38230db 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ print(result[2].meta)
     AssTagAlignment(alignment=5, legacy=False),
     AssTagPosition(x=175.0, y=460.0),
     AssTagFontName(name="Utopia with Oldstyle figures"),
-    AssTagFontSize(size=90),
+    AssTagFontSize(size=90.0),
     AssTagBorder(size=0.0),
     AssTagBlurEdgesGauss(weight=3.0),
     AssTagColor(red=19, green=19, blue=19, target=1, short=False),
diff --git a/ass_tag_parser/ass_parser.py b/ass_tag_parser/ass_parser.py
index 1ee3714..98ad6aa 100644
--- a/ass_tag_parser/ass_parser.py
+++ b/ass_tag_parser/ass_parser.py
@@ -497,7 +497,7 @@ _PARSING_MAP = [
     (r"\fn", AssTagFontName, _single_arg),
     (r"\fscx", AssTagFontXScale, _positive_float_arg),
     (r"\fscy", AssTagFontYScale, _positive_float_arg),
-    (r"\fs", AssTagFontSize, _positive_int_arg),
+    (r"\fs", AssTagFontSize, _positive_float_arg),
     (r"\fe", AssTagFontEncoding, _positive_int_arg),
     (r"\blur", AssTagBlurEdgesGauss, _positive_float_arg),
     (r"\be", AssTagBlurEdges, _positive_int_arg),
diff --git a/ass_tag_parser/tests/test_ass_parsing.py b/ass_tag_parser/tests/test_ass_parsing.py
index 961dff3..931f37c 100644
--- a/ass_tag_parser/tests/test_ass_parsing.py
+++ b/ass_tag_parser/tests/test_ass_parsing.py
@@ -356,7 +356,8 @@ def test_parsing_valid_ass_line(
         (r"{\fnComic Sans}", AssTagFontName(name="Comic Sans")),
         (r"{\fe5}", AssTagFontEncoding(encoding=5)),
         (r"{\fe}", AssTagFontEncoding(encoding=None)),
-        (r"{\fs15}", AssTagFontSize(size=15)),
+        (r"{\fs15}", AssTagFontSize(size=15.0)),
+        (r"{\fs5.5}", AssTagFontSize(size=5.5)),
         (r"{\fs}", AssTagFontSize(size=None)),
         (r"{\fscx5.5}", AssTagFontXScale(scale=5.5)),
         (r"{\fscy5.5}", AssTagFontYScale(scale=5.5)),
@@ -618,7 +619,7 @@ def test_parsing_valid_single_tag(
         ),
         (
             r"{\fs-5}",
-            r"syntax error at pos 6: \fs takes only positive integers",
+            r"syntax error at pos 6: \fs takes only positive decimals",
         ),
         (
             r"{\fscx-5.5}",
@@ -864,7 +865,6 @@ def test_parsing_valid_single_tag(
         (r"{\1a&HFF&derp}", "syntax error at pos 9: extra data"),
         (r"{\be2a}", r"syntax error at pos 6: \be requires an integer"),
         (r"{\be2.2}", r"syntax error at pos 7: \be requires an integer"),
-        (r"{\fs5.4}", r"syntax error at pos 7: \fs requires an integer"),
         (r"{\kgarbage}", r"syntax error at pos 10: \k requires a decimal"),
         (r"{\Kgarbage}", r"syntax error at pos 10: \K requires a decimal"),
         (r"{\kfgarbage}", r"syntax error at pos 11: \kf requires a decimal"),

I don't have any citation.

For the moment, I can give you this: https://slow.pics/c/5JT0MRJb

I will inform myself to see if I can provide you any documentation about it.

Edit: it seems to be the same thing for blur and be tag

Edit: libass does not care of the number type. You can write a decimal for a integer field and it will still work. I think you should just accept any number for all tag that require a number. The subtitle provider will always do it's job to display it.

You can write a decimal for a integer field and it will still work.

I mean it will work, but will it actually use the decimal point, or treat {\fs15.5} the same as if it was {\fs15comment}?

I mean it will work, but will it actually use the decimal point, or treat {\fs15.5} the same as if it was {\fs15comment}?

This depends on implementation. The most common vsfilter implementation, xy-VSFilter, has done so since 2012 Cyberbeing/xy-VSFilter@404301a, and libass has done so since 2007: libass/libass@66bfd7d. The only one I know of which parses it as an integer and discards the rest is the one used by MPC-HC.

See libass/libass#420 for more details and samples of this. In either case, this should never produce an error, in my opinion, as at least one major renderer does support them..