Giter VIP home page Giter VIP logo

ass_tag_parser's Introduction

ass_tag_parser

Build

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

Not to confuse with parsing .ass files that can be manipulated with ass_parser.

Example:

from ass_tag_parser import parse_ass


result = parse_ass(
    r"{\an5\pos(175,460)\fnUtopia with Oldstyle figures\fs90\bord0\blur3"
    r"\1c&H131313&\t(0,1000,2,\1c&H131340&)\t(1000,2000,\1c&H1015B2&"
    r"\blur1.4)}Attack No. 1{NOTE:アタックNo.1}"
)
print(result)
print(result[2].meta)

Result:

[
    AssTagListOpening(),
    AssTagAlignment(alignment=5, legacy=False),
    AssTagPosition(x=175.0, y=460.0),
    AssTagFontName(name="Utopia with Oldstyle figures"),
    AssTagFontSize(size=90.0),
    AssTagBorder(size=0.0),
    AssTagBlurEdgesGauss(weight=3.0),
    AssTagColor(red=19, green=19, blue=19, target=1, short=False),
    AssTagAnimation(
        tags=[AssTagColor(red=64, green=19, blue=19, target=1, short=False)],
        time1=0.0,
        time2=1000.0,
        acceleration=2.0,
    ),
    AssTagAnimation(
        tags=[
            AssTagColor(red=178, green=21, blue=16, target=1, short=False),
            AssTagBlurEdgesGauss(weight=1.4),
        ],
        time1=1000.0,
        time2=2000.0,
        acceleration=None,
    ),
    AssTagListEnding(),
    AssText(text="Attack No. 1"),
    AssTagListOpening(),
    AssTagComment(text="NOTE:アタックNo.1"),
    AssTagListEnding(),
]
Meta(start=5, end=18, text="\\pos(175,460)")

Starting from version 2.2, drawing commands are parsed automatically.


Serializing the tree back

ASS tree: compose_ass. Note that you don't need to supply AssTagListOpening nor AssTagListEnding tags in the input item list – this function inserts them automatically.

Draw commands: compose_draw_commands.

Contributing

# Clone the repository:
git clone https://github.com/bubblesub/ass_tag_parser.git
cd ass_tag_parser

# Install to a local venv:
poetry install

# Install pre-commit hooks:
poetry run pre-commit install

# Enter the venv:
poetry shell

This project uses poetry for packaging, install instructions at poetry#installation

ass_tag_parser's People

Contributors

luni-4 avatar rr- avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

ass_tag_parser's Issues

This package cannot be installed on non-English windows systems

PS C:\xxx> pip install ass-tag-parser
Collecting ass-tag-parser
  Using cached https://xxx/ass_tag_parser-2.3.tar.gz (16 kB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\xxx\\AppData\\Local\\Temp\\pip-install-1s17sz2y\\ass-tag-parser\\setup.py'"'"'; __file__='"'"'C:\\Users\\xxx\\AppData\\Local\\Temp\\pip-install-1s17sz2y\\ass-tag-parser\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\xxx\AppData\Local\Temp\pip-pip-egg-info-7kr7ks__'
         cwd: C:\Users\xxx\AppData\Local\Temp\pip-install-1s17sz2y\ass-tag-parser\
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\xxx\AppData\Local\Temp\pip-install-1s17sz2y\ass-tag-parser\setup.py", line 11, in <module>
        long_description=(Path(__file__).parent / "README.md").read_text(),
      File "c:\python38\lib\pathlib.py", line 1236, in read_text
        return f.read()
    UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 601: illegal multibyte sequence
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

There are different default encodings in these operating systems (for open etc.)

Don't raise an exception, simply have a class for unknow tag

Currently, ass_tag_parser can't parse VSFilterMod tag which is totally ok, because they have they are useless.

But, it would be better if it could not raise an exception. It should simply have a class for unknowtag.

Here is the code I have:

result = parse_ass(
    r"{\fnJester\fsc20}test"
)
print(result)

What it currently does:
ass_tag_parser.errors.BadAssTagArgument: syntax error at pos 16: \fs requires an integer

What it could do:
[AssTagListOpening(), AssTagFontName(name='Jester'), AssUnknowTag(text=fsc20), AssTagListEnding(), AssText(text='test')]

\fs should accept float number

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.

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.