easyass


Nameeasyass JSON
Version 1.0.0b11 PyPI version JSON
download
home_pagehttps://github.com/hihkm/easyAss
SummaryAn ass subtitle parsing library
upload_time2023-09-11 17:02:38
maintainer
docs_urlNone
authortikm
requires_python>=3.7
licenseMIT Licence
keywords ass subtitle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # easy ass

一个用于解析和操作ass字幕的python包

⚠️当前处于开发阶段,未经过严格测试

### 功能
✅ ScriptInfo、Styles、Events解析

✅ 大部分的覆写控制代码支持

✅ 字段类型,合法性检查

⬜ 绘图指令、方便的绘图支持(开发中)

~~⬜ C++内核实现 (计划)~~

### 安装
从 pip 中获取

``` shell
pip install easyass
```

支持 python 3.7 及以上版本,没有额外的库依赖。

### 例子

```python
from easyass import *  # 引入 easyass 包

# 库不提供直接读取文件的api,需要自行读写
with open(r'test/test.ass', 'r', encoding='utf8') as fp:  # 读一个 ass 文件
    ass_str = fp.read()

ass_obj = Ass()  # 创建一个 ass 实例
errs = ass_obj.parse(ass_str)  # 解析 ass 文本
print(ass.script_info.Title)  # 输出 title
ass_obj.script_info.Title = 'aabbcc'  # 修改 title

print(ass_obj.styles[0].Name)  # 获取第一条 styles 的名字
ass_obj.styles.append(StyleItem(  # 添加一个 style 并指定其部分字段
    Name='r2l',
    Fontname='Microsoft YaHei',
    Fontsize=30,
))

print(ass_obj.events[0].Start)  # 获取第一条事件的开始时间
ass_obj.events[0].Text = 'good'  # 修改第一条事件的文本
# 修改第一条事件的文本,并使用覆写代码
ass_obj.events[0].Text = Pos(1, 10) + 'good' + FontSize(size=30)
ass_obj.events[0].Text[0].x = 60  # 修改刚才添加的覆写代码中 Pos 的属性 x, 具体属性见 docstring
print(ass_obj.events[0].dump())  # 获取第一条事件的 ass 代码

lines, errs = ass_obj.dump()
with open(r'op.ass', 'w', encoding='utf8') as fp:  # 修改后的ass写到文件
    fp.write('\n'.join(lines))  # lines是一个字符串数组,包含每一行的内容
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hihkm/easyAss",
    "name": "easyass",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "ass,subtitle",
    "author": "tikm",
    "author_email": "hkm@tikm.org",
    "download_url": "https://files.pythonhosted.org/packages/93/06/08e3491a03f97ef6c4903b0f6be6647ffa1470a8e5329463f146f34b4b5b/easyass-1.0.0b11.tar.gz",
    "platform": "all",
    "description": "# easy ass\r\n\r\n\u4e00\u4e2a\u7528\u4e8e\u89e3\u6790\u548c\u64cd\u4f5cass\u5b57\u5e55\u7684python\u5305\r\n\r\n\u26a0\ufe0f\u5f53\u524d\u5904\u4e8e\u5f00\u53d1\u9636\u6bb5\uff0c\u672a\u7ecf\u8fc7\u4e25\u683c\u6d4b\u8bd5\r\n\r\n### \u529f\u80fd\r\n\u2705 ScriptInfo\u3001Styles\u3001Events\u89e3\u6790\r\n\r\n\u2705 \u5927\u90e8\u5206\u7684\u8986\u5199\u63a7\u5236\u4ee3\u7801\u652f\u6301\r\n\r\n\u2705 \u5b57\u6bb5\u7c7b\u578b\uff0c\u5408\u6cd5\u6027\u68c0\u67e5\r\n\r\n\u2b1c \u7ed8\u56fe\u6307\u4ee4\u3001\u65b9\u4fbf\u7684\u7ed8\u56fe\u652f\u6301\uff08\u5f00\u53d1\u4e2d\uff09\r\n\r\n~~\u2b1c C++\u5185\u6838\u5b9e\u73b0 \uff08\u8ba1\u5212\uff09~~\r\n\r\n### \u5b89\u88c5\r\n\u4ece pip \u4e2d\u83b7\u53d6\r\n\r\n``` shell\r\npip install easyass\r\n```\r\n\r\n\u652f\u6301 python 3.7 \u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u6ca1\u6709\u989d\u5916\u7684\u5e93\u4f9d\u8d56\u3002\r\n\r\n### \u4f8b\u5b50\r\n\r\n```python\r\nfrom easyass import *  # \u5f15\u5165 easyass \u5305\r\n\r\n# \u5e93\u4e0d\u63d0\u4f9b\u76f4\u63a5\u8bfb\u53d6\u6587\u4ef6\u7684api\uff0c\u9700\u8981\u81ea\u884c\u8bfb\u5199\r\nwith open(r'test/test.ass', 'r', encoding='utf8') as fp:  # \u8bfb\u4e00\u4e2a ass \u6587\u4ef6\r\n    ass_str = fp.read()\r\n\r\nass_obj = Ass()  # \u521b\u5efa\u4e00\u4e2a ass \u5b9e\u4f8b\r\nerrs = ass_obj.parse(ass_str)  # \u89e3\u6790 ass \u6587\u672c\r\nprint(ass.script_info.Title)  # \u8f93\u51fa title\r\nass_obj.script_info.Title = 'aabbcc'  # \u4fee\u6539 title\r\n\r\nprint(ass_obj.styles[0].Name)  # \u83b7\u53d6\u7b2c\u4e00\u6761 styles \u7684\u540d\u5b57\r\nass_obj.styles.append(StyleItem(  # \u6dfb\u52a0\u4e00\u4e2a style \u5e76\u6307\u5b9a\u5176\u90e8\u5206\u5b57\u6bb5\r\n    Name='r2l',\r\n    Fontname='Microsoft YaHei',\r\n    Fontsize=30,\r\n))\r\n\r\nprint(ass_obj.events[0].Start)  # \u83b7\u53d6\u7b2c\u4e00\u6761\u4e8b\u4ef6\u7684\u5f00\u59cb\u65f6\u95f4\r\nass_obj.events[0].Text = 'good'  # \u4fee\u6539\u7b2c\u4e00\u6761\u4e8b\u4ef6\u7684\u6587\u672c\r\n# \u4fee\u6539\u7b2c\u4e00\u6761\u4e8b\u4ef6\u7684\u6587\u672c\uff0c\u5e76\u4f7f\u7528\u8986\u5199\u4ee3\u7801\r\nass_obj.events[0].Text = Pos(1, 10) + 'good' + FontSize(size=30)\r\nass_obj.events[0].Text[0].x = 60  # \u4fee\u6539\u521a\u624d\u6dfb\u52a0\u7684\u8986\u5199\u4ee3\u7801\u4e2d Pos \u7684\u5c5e\u6027 x, \u5177\u4f53\u5c5e\u6027\u89c1 docstring\r\nprint(ass_obj.events[0].dump())  # \u83b7\u53d6\u7b2c\u4e00\u6761\u4e8b\u4ef6\u7684 ass \u4ee3\u7801\r\n\r\nlines, errs = ass_obj.dump()\r\nwith open(r'op.ass', 'w', encoding='utf8') as fp:  # \u4fee\u6539\u540e\u7684ass\u5199\u5230\u6587\u4ef6\r\n    fp.write('\\n'.join(lines))  # lines\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5305\u542b\u6bcf\u4e00\u884c\u7684\u5185\u5bb9\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT Licence",
    "summary": "An ass subtitle parsing library",
    "version": "1.0.0b11",
    "project_urls": {
        "Homepage": "https://github.com/hihkm/easyAss"
    },
    "split_keywords": [
        "ass",
        "subtitle"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0024c0d804ac1c41a1b472dcd0b0fc2a0bb13f574960565fdfb9f1054a7dd0b",
                "md5": "ecb1393a6e0f5f2f86e20caf1f9ac3a2",
                "sha256": "4da79f728150fe3f33cfbb37aa090b67a36f4d363728e695d9a41f63bd784624"
            },
            "downloads": -1,
            "filename": "easyass-1.0.0b11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ecb1393a6e0f5f2f86e20caf1f9ac3a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 18365,
            "upload_time": "2023-09-11T17:02:36",
            "upload_time_iso_8601": "2023-09-11T17:02:36.034743Z",
            "url": "https://files.pythonhosted.org/packages/c0/02/4c0d804ac1c41a1b472dcd0b0fc2a0bb13f574960565fdfb9f1054a7dd0b/easyass-1.0.0b11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "930608e3491a03f97ef6c4903b0f6be6647ffa1470a8e5329463f146f34b4b5b",
                "md5": "2f96f2aeb8116e9e4761031be11fdce9",
                "sha256": "aeb6bf389af5e0dd1ec4d4371baf3cf135697bf360b63a21f0a67e2a89094b54"
            },
            "downloads": -1,
            "filename": "easyass-1.0.0b11.tar.gz",
            "has_sig": false,
            "md5_digest": "2f96f2aeb8116e9e4761031be11fdce9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 15693,
            "upload_time": "2023-09-11T17:02:38",
            "upload_time_iso_8601": "2023-09-11T17:02:38.050355Z",
            "url": "https://files.pythonhosted.org/packages/93/06/08e3491a03f97ef6c4903b0f6be6647ffa1470a8e5329463f146f34b4b5b/easyass-1.0.0b11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-11 17:02:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hihkm",
    "github_project": "easyAss",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "easyass"
}
        
Elapsed time: 1.65830s