Skip to content

Commit 7d39f6f

Browse files
committed
use fps instead of frameskip and allow format filter
1 parent ebc6f67 commit 7d39f6f

File tree

10 files changed

+290
-236
lines changed

10 files changed

+290
-236
lines changed

documentation/reference/tstickers/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## cli
1111

12-
[Show source in cli.py:18](../../../tstickers/cli.py#L18)
12+
[Show source in cli.py:20](../../../tstickers/cli.py#L20)
1313

1414
Cli entry point.
1515

documentation/reference/tstickers/convert.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,38 @@ class Backend(IntEnum): ...
2727

2828
## convertAnimated
2929

30-
[Show source in convert.py:90](../../../tstickers/convert.py#L90)
30+
[Show source in convert.py:87](../../../tstickers/convert.py#L87)
3131

32-
Convert animated stickers to webp, gif and png.
32+
Convert animated stickers, over a number of threads, at a given framerate, scale and to a
33+
set of formats.
3334

3435
#### Arguments
3536

36-
----
37-
- `swd` *Path* - the sticker working directory (downloads/packName)
38-
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults
39-
to number of cores/ logical processors.
40-
- `frameSkip` *int, optional* - skip n number of frames in the interest of
41-
optimisation with a quality trade-off. Defaults to 1.
42-
- `scale` *float, optional* - upscale/ downscale the images produced. Intended
43-
for optimisation with a quality trade-off. Defaults to 1.
44-
- `backend` *Backend* - The backend to use for conversion. Defaults to Backend.UNDEFINED,
45-
allowing the system to determine the appropriate library to use.
37+
- `swd` *Path* - The sticker working directory (e.g., downloads/packName).
38+
- `threads` *int* - Number of threads for ProcessPoolExecutor (default: number of
39+
logical processors).
40+
- `fps` *int* - framerate of the converted sticker, affecting optimization and
41+
quality (default: 20)
42+
- `scale` *float* - Scale factor for up/downscaling images, affecting optimization and
43+
quality (default: 1).
44+
:param set[str]|None formats: Set of formats to convert telegram tgs stickers to
45+
(default: {"gif", "webp", "apng"})
4646

4747
#### Returns
4848

49-
-------
50-
- `int` - number of stickers successfully converted
49+
Type: *int*
50+
Number of stickers successfully converted.
5151

5252
#### Signature
5353

5454
```python
5555
def convertAnimated(
5656
swd: Path,
5757
threads: int = multiprocessing.cpu_count(),
58-
frameSkip: int = 1,
58+
fps: int = 20,
5959
scale: float = 1,
6060
backend: Backend = Backend.UNDEFINED,
61+
formats: set[str] | None = None,
6162
) -> int: ...
6263
```
6364

@@ -77,33 +78,37 @@ Convert animated stickers with (Base/Backend.UNDEFINED).
7778

7879
```python
7980
def convertAnimatedFunc(
80-
_swd: Path, _threads: int, _frameSkip: int, _scale: float
81+
_swd: Path, _threads: int, _fps: int, _scale: float, _formats
8182
) -> int: ...
8283
```
8384

8485

8586

8687
## convertStatic
8788

88-
[Show source in convert.py:58](../../../tstickers/convert.py#L58)
89+
[Show source in convert.py:56](../../../tstickers/convert.py#L56)
8990

90-
Convert static stickers to png and gif.
91+
Convert static stickers to specified formats.
9192

9293
#### Arguments
9394

94-
----
95-
- `swd` *Path* - the sticker working directory (downloads/packName)
96-
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults to 4.
95+
- `swd` *Path* - The sticker working directory (e.g., downloads/packName).
96+
- `threads` *int* - Number of threads for ProcessPoolExecutor (default: number of
97+
logical processors).
98+
:param set[str]|None formats: Set of formats to convert telegram webp stickers to
99+
(default: {"gif", "png", "webp", "apng"})
97100

98101
#### Returns
99102

100-
-------
101-
- `int` - number of stickers successfully converted
103+
Type: *int*
104+
Number of stickers successfully converted.
102105

103106
#### Signature
104107

105108
```python
106-
def convertStatic(swd: Path, threads: int = 4) -> int: ...
109+
def convertStatic(
110+
swd: Path, threads: int = 4, formats: set[str] | None = None
111+
) -> int: ...
107112
```
108113

109114

@@ -112,20 +117,20 @@ def convertStatic(swd: Path, threads: int = 4) -> int: ...
112117

113118
[Show source in convert.py:38](../../../tstickers/convert.py#L38)
114119

115-
Convert the webp file to png.
120+
Convert a webp file to specified formats.
116121

117122
#### Arguments
118123

119-
----
120-
- `inputFile` *str* - path to input file
124+
- `input_file` *Path* - path to the input image/ sticker
125+
:param set[str] formats: set of formats
121126

122127
#### Returns
123128

124-
-------
125-
- `str` - path to input file
129+
Type: *Path*
130+
path of the original image/sticker file
126131

127132
#### Signature
128133

129134
```python
130-
def convertWithPIL(inputFile: str) -> str: ...
135+
def convertWithPIL(input_file: Path, formats: set[str]) -> Path: ...
131136
```

documentation/reference/tstickers/convert_pyrlottie.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,34 @@
99

1010
## convertAnimated
1111

12-
[Show source in convert_pyrlottie.py:26](../../../tstickers/convert_pyrlottie.py#L26)
12+
[Show source in convert_pyrlottie.py:17](../../../tstickers/convert_pyrlottie.py#L17)
1313

14-
Convert animated stickers to webp, gif and png.
14+
Convert animated stickers, over a number of threads, at a given framerate, scale and to a
15+
set of formats.
1516

1617
#### Arguments
1718

18-
----
19-
- `swd` *Path* - the sticker working directory (downloads/packName)
20-
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults to 4.
21-
- `frameSkip` *int, optional* - skip n number of frames in the interest of
22-
optimisation with a quality trade-off. Defaults to 1.
23-
- `scale` *float, optional* - upscale/ downscale the images produced. Intended
24-
for optimisation with a quality trade-off. Defaults to 1.
19+
- `swd` *Path* - The sticker working directory (e.g., downloads/packName).
20+
- `_threads` *int* - This is ignored for the pyrlottie backend
21+
- `fps` *int* - framerate of the converted sticker, affecting optimization and
22+
quality (default: 20)
23+
- `scale` *float* - Scale factor for up/downscaling images, affecting optimization and
24+
quality (default: 1).
25+
:param set[str] | None _formats: This is ignored for the pyrlottie backend
2526

2627
#### Returns
2728

28-
-------
29-
- `int` - number of stickers successfully converted
29+
Type: *int*
30+
Number of stickers successfully converted.
3031

3132
#### Signature
3233

3334
```python
3435
def convertAnimated(
35-
swd: Path, _threads: int = 4, frameSkip: int = 1, scale: float = 1
36+
swd: Path,
37+
_threads: int = 4,
38+
fps: int = 20,
39+
scale: float = 1,
40+
_formats: set[str] | None = None,
3641
) -> int: ...
3742
```

documentation/reference/tstickers/convert_rlottie_python.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,67 @@
1010

1111
## convertAnimated
1212

13-
[Show source in convert_rlottie_python.py:49](../../../tstickers/convert_rlottie_python.py#L49)
13+
[Show source in convert_rlottie_python.py:59](../../../tstickers/convert_rlottie_python.py#L59)
1414

15-
Convert animated stickers to webp, gif and png.
15+
Convert animated stickers, over a number of threads, at a given framerate, scale and to a
16+
set of formats.
1617

1718
#### Arguments
1819

19-
----
20-
- `swd` *Path* - the sticker working directory (downloads/packName)
21-
- `threads` *int, optional* - number of threads to pass to ProcessPoolExecutor. Defaults
22-
to number of cores/ logical processors.
23-
- `frameSkip` *int, optional* - skip n number of frames in the interest of
24-
optimisation with a quality trade-off. Defaults to 1.
25-
- `scale` *float, optional* - upscale/ downscale the images produced. Intended
26-
for optimisation with a quality trade-off. Defaults to 1.
20+
- `swd` *Path* - The sticker working directory (e.g., downloads/packName).
21+
- `threads` *int* - Number of threads for ProcessPoolExecutor (default: number of
22+
logical processors).
23+
- `fps` *int* - framerate of the converted sticker, affecting optimization and
24+
quality (default: 20)
25+
- `scale` *float* - Scale factor for up/downscaling images, affecting optimization and
26+
quality (default: 1).
27+
:param set[str]|None formats: Set of formats to convert telegram tgs stickers to
28+
(default: {"gif", "webp", "apng"})
2729

2830
#### Returns
2931

30-
-------
31-
- `int` - number of stickers successfully converted
32+
Type: *int*
33+
Number of stickers successfully converted.
3234

3335
#### Signature
3436

3537
```python
3638
def convertAnimated(
3739
swd: Path,
3840
threads: int = multiprocessing.cpu_count(),
39-
frameSkip: int = 1,
41+
fps: int = 20,
4042
scale: float = 1,
43+
formats: set[str] | None = None,
4144
) -> int: ...
4245
```
4346

4447

4548

4649
## convert_single_tgs
4750

48-
[Show source in convert_rlottie_python.py:26](../../../tstickers/convert_rlottie_python.py#L26)
51+
[Show source in convert_rlottie_python.py:18](../../../tstickers/convert_rlottie_python.py#L18)
52+
53+
Convert a single tgs file.
54+
55+
#### Arguments
56+
57+
- `stckr` *Path* - Path to the sticker
58+
- `fps` *int* - framerate of the converted sticker, affecting optimization and
59+
quality (default: 20)
60+
- `scale` *float* - Scale factor for up/downscaling images, affecting optimization and
61+
quality (default: 1).
62+
:param set[str]|None formats: Set of formats to convert telegram tgs stickers to
63+
(default: {"gif", "webp", "apng"})
64+
65+
#### Returns
66+
67+
Type: *int*
68+
1 if success
4969

5070
#### Signature
5171

5272
```python
53-
def convert_single_tgs(stckr: Path, fps: int, scale: float = 1.0) -> int: ...
73+
def convert_single_tgs(
74+
stckr: Path, fps: int, scale: float = 1.0, formats: set[str] | None = None
75+
) -> int: ...
5476
```

documentation/reference/tstickers/manager.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,33 @@ class StickerManager:
7777

7878
### StickerManager().convertPack
7979

80-
[Show source in manager.py:256](../../../tstickers/manager.py#L256)
80+
[Show source in manager.py:248](../../../tstickers/manager.py#L248)
8181

82-
Convert the webp to gif and png; tgs to gif, webp (webp_animated) and png.
82+
Convert a downloaded sticker pack given by packName to other formats specified.
8383

8484
#### Arguments
8585

86-
----
87-
- `packName` *str* - name of the directory to convert
88-
- `frameSkip` *int, optional* - skip n number of frames in the interest of
89-
optimisation with a quality trade-off. Defaults to 1.
90-
- `scale` *float, optional* - upscale/ downscale the images produced. Intended
91-
for optimisation with a quality trade-off. Defaults to 1.
92-
- `noCache` *bool, optional* - set to true to disable cache. Defaults to False.
93-
- `backend` *Backend* - select the backend to use to convert animated stickers
86+
- `packName` *str* - name of the pack to convert
87+
- `fps` *int* - framerate of animated stickers, affecting optimization and
88+
quality (default: 20)
89+
- `scale` *float* - Scale factor of animated stickers, for up/downscaling images,
90+
affecting optimization and quality (default: 1).
91+
- `noCache` *bool* - set to true to disable cache. Defaults to False.
92+
- `backend` *Backend* - select the backend to use to convert animated stickers
93+
:param set[str]|None formats: Set of formats to convert telegram tgs stickers to
94+
(default: {"gif", "webp", "apng"})
9495

9596
#### Signature
9697

9798
```python
9899
def convertPack(
99100
self,
100101
packName: str,
101-
frameSkip: int = 1,
102+
fps: int = 20,
102103
scale: float = 1,
103104
noCache: bool = False,
104105
backend: Backend = Backend.UNDEFINED,
106+
formats: set[str] | None = None,
105107
) -> None: ...
106108
```
107109

@@ -139,19 +141,18 @@ def doAPIReq(self, function: str, params: dict[Any, Any]) -> dict[Any, Any] | No
139141

140142
### StickerManager().downloadPack
141143

142-
[Show source in manager.py:210](../../../tstickers/manager.py#L210)
144+
[Show source in manager.py:207](../../../tstickers/manager.py#L207)
143145

144146
Download a sticker pack.
145147

146148
#### Arguments
147149

148-
----
149-
- `packName` *str* - name of the pack
150+
- `packName` *str* - name of the pack
150151

151152
#### Returns
152153

153-
-------
154-
- `bool` - success
154+
Type: *bool*
155+
success
155156

156157
#### Signature
157158

@@ -167,14 +168,13 @@ Download a sticker from the server.
167168

168169
#### Arguments
169170

170-
----
171-
- `path` *Path* - the path to write to
172-
- `link` *str* - the url to the file on the server
171+
- `path` *Path* - the path to write to
172+
- `link` *str* - the url to the file on the server
173173

174174
#### Returns
175175

176-
-------
177-
- `int` - path.write_bytes(res.content)
176+
Type: *int*
177+
path.write_bytes(res.content)
178178

179179
#### Signature
180180

0 commit comments

Comments
 (0)