Skip to content

Commit bee9c8f

Browse files
authored
⚰️ chore(biliass): reorganize apis (#342)
1 parent 69aa775 commit bee9c8f

File tree

9 files changed

+10
-232
lines changed

9 files changed

+10
-232
lines changed

packages/biliass/rust/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ impl std::convert::From<BiliassError> for PyErr {
2020
#[pymodule]
2121
#[pyo3(name = "_core")]
2222
fn biliass_pyo3(m: &Bound<'_, PyModule>) -> PyResult<()> {
23-
m.add_class::<python::PyDmSegMobileReply>()?;
24-
m.add_class::<python::PyDanmakuElem>()?;
25-
m.add_class::<python::PyComment>()?;
26-
m.add_class::<python::PyCommentPosition>()?;
2723
m.add_function(wrap_pyfunction!(python::py_get_danmaku_meta_size, m)?)?;
28-
m.add_function(wrap_pyfunction!(python::py_read_comments_from_xml, m)?)?;
29-
m.add_function(wrap_pyfunction!(python::py_read_comments_from_protobuf, m)?)?;
30-
m.add_function(wrap_pyfunction!(python::py_parse_special_comment, m)?)?;
3124
m.add_function(wrap_pyfunction!(python::py_xml_to_ass, m)?)?;
3225
m.add_function(wrap_pyfunction!(python::py_protobuf_to_ass, m)?)?;
3326
Ok(())

packages/biliass/rust/src/python/comment.rs

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
mod comment;
21
mod convert;
32
mod proto;
4-
mod reader;
53

6-
pub use comment::{PyComment, PyCommentPosition};
74
pub use convert::{py_protobuf_to_ass, py_xml_to_ass};
8-
pub use proto::{py_get_danmaku_meta_size, PyDanmakuElem, PyDmSegMobileReply};
9-
pub use reader::{
10-
py_parse_special_comment, py_read_comments_from_protobuf, py_read_comments_from_xml,
11-
};
5+
pub use proto::py_get_danmaku_meta_size;

packages/biliass/rust/src/python/reader.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/biliass/src/biliass/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
from .biliass import (
66
Danmaku2ASS as Danmaku2ASS,
77
convert_to_ass as convert_to_ass,
8-
read_comments_bilibili_protobuf as read_comments_bilibili_protobuf,
9-
read_comments_bilibili_xml as read_comments_bilibili_xml,
108
)

packages/biliass/src/biliass/_core.pyi

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,3 @@
1-
from typing import ClassVar
2-
3-
class DanmakuElem:
4-
@property
5-
def id(self) -> int: ...
6-
@property
7-
def progress(self) -> int: ...
8-
@property
9-
def mode(self) -> int: ...
10-
@property
11-
def fontsize(self) -> int: ...
12-
@property
13-
def color(self) -> int: ...
14-
@property
15-
def mid_hash(self) -> str: ...
16-
@property
17-
def content(self) -> str: ...
18-
@property
19-
def ctime(self) -> int: ...
20-
@property
21-
def action(self) -> str: ...
22-
@property
23-
def pool(self) -> int: ...
24-
@property
25-
def id_str(self) -> str: ...
26-
@property
27-
def attr(self) -> int: ...
28-
@property
29-
def animation(self) -> str: ...
30-
31-
class DmSegMobileReply:
32-
@property
33-
def elems(self) -> list[DanmakuElem]: ...
34-
@staticmethod
35-
def decode(data: bytes) -> DmSegMobileReply: ...
36-
37-
class CommentPosition:
38-
Scroll: ClassVar[CommentPosition]
39-
Top: ClassVar[CommentPosition]
40-
Bottom: ClassVar[CommentPosition]
41-
Reversed: ClassVar[CommentPosition]
42-
Special: ClassVar[CommentPosition]
43-
44-
@property
45-
def id(self) -> int: ...
46-
47-
class Comment:
48-
timeline: float
49-
timestamp: int
50-
no: int
51-
comment: str
52-
pos: CommentPosition
53-
color: int
54-
size: float
55-
height: float
56-
width: float
57-
58-
def read_comments_from_xml(text: str, fontsize: float) -> list[Comment]: ...
59-
def read_comments_from_protobuf(data: bytes, fontsize: float) -> list[Comment]: ...
60-
def parse_special_comment(
61-
content: str, zoom_factor: tuple[float, float, float]
62-
) -> tuple[tuple[int, int, float, float, float, float], int, int, str, int, float, int, str, bool]: ...
631
def xml_to_ass(
642
inputs: list[str],
653
stage_width: int,

packages/biliass/src/biliass/biliass.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
from __future__ import annotations
22

3-
from collections.abc import Callable
4-
from typing import TypeVar, cast
3+
from typing import TYPE_CHECKING, TypeVar, cast
54

65
from biliass._core import (
7-
Comment,
86
protobuf_to_ass,
9-
read_comments_from_protobuf,
10-
read_comments_from_xml,
117
xml_to_ass,
128
)
139

14-
T = TypeVar("T")
15-
16-
17-
def read_comments_bilibili_xml(text: str | bytes, fontsize: float) -> list[Comment]:
18-
if isinstance(text, bytes):
19-
text = text.decode()
20-
return read_comments_from_xml(text, fontsize)
10+
if TYPE_CHECKING:
11+
from collections.abc import Callable
2112

22-
23-
def read_comments_bilibili_protobuf(protobuf: bytes | str, fontsize: float) -> list[Comment]:
24-
assert isinstance(protobuf, bytes), "protobuf supports bytes only"
25-
return read_comments_from_protobuf(protobuf, fontsize)
13+
T = TypeVar("T")
2614

2715

2816
def Danmaku2ASS(

tests/test_biliass/test_protobuf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import httpx
66
import pytest
7-
from biliass import read_comments_bilibili_protobuf
7+
from biliass import convert_to_ass
88

99
from ..conftest import DEFAULT_HEADERS, TEST_DIR
1010

@@ -28,4 +28,4 @@ def gen_protobuf(base_dir: Path):
2828
def test_protobuf():
2929
gen_protobuf(TEST_DIR)
3030
with TEST_DIR.joinpath("test.pb").open("rb") as f:
31-
list(read_comments_bilibili_protobuf(f.read(), 10))
31+
convert_to_ass(f.read(), 1920, 1080, input_format="protobuf")

tests/test_biliass/test_xml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import httpx
66
import pytest
7-
from biliass import read_comments_bilibili_xml
7+
from biliass import convert_to_ass
88

99
from ..conftest import DEFAULT_HEADERS, TEST_DIR
1010

@@ -30,11 +30,11 @@ def gen_xml_v1(base_dir: Path):
3030
def test_xml_v1_text():
3131
gen_xml_v1(TEST_DIR)
3232
with TEST_DIR.joinpath("test_v1.xml").open("r") as f:
33-
list(read_comments_bilibili_xml(f.read(), 10))
33+
convert_to_ass(f.read(), 1920, 1080)
3434

3535

3636
@pytest.mark.biliass
3737
def test_xml_v1_bytes():
3838
gen_xml_v1(TEST_DIR)
3939
with TEST_DIR.joinpath("test_v1.xml").open("rb") as f:
40-
list(read_comments_bilibili_xml(f.read(), 10))
40+
convert_to_ass(f.read(), 1920, 1080)

0 commit comments

Comments
 (0)