sticker-convert 2.13.3.0__py3-none-any.whl → 2.17.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sticker_convert/__main__.py +24 -27
- sticker_convert/auth/__init__.py +0 -0
- sticker_convert/auth/auth_base.py +19 -0
- sticker_convert/{utils/auth/get_discord_auth.py → auth/auth_discord.py} +149 -118
- sticker_convert/{utils/auth/get_kakao_auth.py → auth/auth_kakao_android_login.py} +331 -330
- sticker_convert/auth/auth_kakao_desktop_login.py +327 -0
- sticker_convert/{utils/auth/get_kakao_desktop_auth.py → auth/auth_kakao_desktop_memdump.py} +281 -263
- sticker_convert/{utils/auth/get_line_auth.py → auth/auth_line.py} +98 -80
- sticker_convert/{utils/auth/get_signal_auth.py → auth/auth_signal.py} +139 -135
- sticker_convert/auth/auth_telethon.py +161 -0
- sticker_convert/{utils/auth/get_viber_auth.py → auth/auth_viber.py} +250 -235
- sticker_convert/{utils/auth → auth}/telegram_api.py +736 -675
- sticker_convert/cli.py +623 -608
- sticker_convert/converter.py +1093 -1084
- sticker_convert/definitions.py +4 -0
- sticker_convert/downloaders/download_band.py +111 -110
- sticker_convert/downloaders/download_base.py +171 -166
- sticker_convert/downloaders/download_discord.py +92 -91
- sticker_convert/downloaders/download_kakao.py +417 -404
- sticker_convert/downloaders/download_line.py +484 -475
- sticker_convert/downloaders/download_ogq.py +80 -79
- sticker_convert/downloaders/download_signal.py +108 -105
- sticker_convert/downloaders/download_telegram.py +56 -55
- sticker_convert/downloaders/download_viber.py +121 -120
- sticker_convert/gui.py +788 -873
- sticker_convert/gui_components/frames/comp_frame.py +180 -166
- sticker_convert/gui_components/frames/config_frame.py +156 -113
- sticker_convert/gui_components/frames/control_frame.py +32 -30
- sticker_convert/gui_components/frames/cred_frame.py +232 -233
- sticker_convert/gui_components/frames/input_frame.py +139 -137
- sticker_convert/gui_components/frames/output_frame.py +112 -110
- sticker_convert/gui_components/frames/right_clicker.py +25 -23
- sticker_convert/gui_components/windows/advanced_compression_window.py +757 -757
- sticker_convert/gui_components/windows/base_window.py +7 -2
- sticker_convert/gui_components/windows/discord_get_auth_window.py +79 -82
- sticker_convert/gui_components/windows/kakao_get_auth_window.py +511 -321
- sticker_convert/gui_components/windows/line_get_auth_window.py +94 -102
- sticker_convert/gui_components/windows/signal_get_auth_window.py +84 -89
- sticker_convert/gui_components/windows/viber_get_auth_window.py +168 -168
- sticker_convert/ios-message-stickers-template/.github/FUNDING.yml +3 -3
- sticker_convert/ios-message-stickers-template/README.md +10 -10
- sticker_convert/ios-message-stickers-template/stickers/Info.plist +43 -43
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Info.plist +31 -31
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Contents.json +6 -6
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Contents.json +20 -20
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Sticker 1.sticker/Contents.json +9 -9
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Sticker 2.sticker/Contents.json +9 -9
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Sticker 3.sticker/Contents.json +9 -9
- sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset/Contents.json +91 -91
- sticker_convert/ios-message-stickers-template/stickers.xcodeproj/project.pbxproj +364 -364
- sticker_convert/ios-message-stickers-template/stickers.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -7
- sticker_convert/ios-message-stickers-template/stickers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- sticker_convert/ios-message-stickers-template/stickers.xcodeproj/xcuserdata/niklaspeterson.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- sticker_convert/job.py +166 -130
- sticker_convert/job_option.py +1 -0
- sticker_convert/locales/en_US/LC_MESSAGES/base.mo +0 -0
- sticker_convert/locales/ja_JP/LC_MESSAGES/base.mo +0 -0
- sticker_convert/locales/zh_CN/LC_MESSAGES/base.mo +0 -0
- sticker_convert/locales/zh_TW/LC_MESSAGES/base.mo +0 -0
- sticker_convert/py.typed +0 -0
- sticker_convert/resources/NotoColorEmoji.ttf +0 -0
- sticker_convert/resources/help.ja_JP.json +88 -0
- sticker_convert/resources/help.json +10 -7
- sticker_convert/resources/help.zh_CN.json +88 -0
- sticker_convert/resources/help.zh_TW.json +88 -0
- sticker_convert/resources/input.ja_JP.json +74 -0
- sticker_convert/resources/input.json +121 -121
- sticker_convert/resources/input.zh_CN.json +74 -0
- sticker_convert/resources/input.zh_TW.json +74 -0
- sticker_convert/resources/output.ja_JP.json +38 -0
- sticker_convert/resources/output.zh_CN.json +38 -0
- sticker_convert/resources/output.zh_TW.json +38 -0
- sticker_convert/uploaders/compress_wastickers.py +186 -177
- sticker_convert/uploaders/upload_base.py +44 -35
- sticker_convert/uploaders/upload_signal.py +218 -203
- sticker_convert/uploaders/upload_telegram.py +353 -338
- sticker_convert/uploaders/upload_viber.py +178 -169
- sticker_convert/uploaders/xcode_imessage.py +295 -286
- sticker_convert/utils/callback.py +238 -6
- sticker_convert/utils/emoji.py +16 -4
- sticker_convert/utils/files/json_resources_loader.py +24 -19
- sticker_convert/utils/files/metadata_handler.py +3 -3
- sticker_convert/utils/translate.py +108 -0
- sticker_convert/utils/url_detect.py +40 -37
- sticker_convert/version.py +1 -1
- {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/METADATA +89 -74
- {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/RECORD +91 -74
- sticker_convert/utils/auth/telethon_setup.py +0 -97
- sticker_convert/utils/singletons.py +0 -18
- {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/WHEEL +0 -0
- {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/entry_points.txt +0 -0
- {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/licenses/LICENSE +0 -0
- {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,338 +1,353 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import copy
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
|
5
|
-
|
|
6
|
-
import anyio
|
|
7
|
-
from telegram import Sticker
|
|
8
|
-
|
|
9
|
-
from sticker_convert.
|
|
10
|
-
from sticker_convert.
|
|
11
|
-
from sticker_convert.
|
|
12
|
-
from sticker_convert.
|
|
13
|
-
from sticker_convert.utils.callback import CallbackProtocol, CallbackReturn
|
|
14
|
-
from sticker_convert.utils.emoji import extract_emojis
|
|
15
|
-
from sticker_convert.utils.files.metadata_handler import MetadataHandler
|
|
16
|
-
from sticker_convert.utils.media.codec_info import CodecInfo
|
|
17
|
-
from sticker_convert.utils.media.format_verify import FormatVerify
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
self.
|
|
32
|
-
|
|
33
|
-
self.
|
|
34
|
-
self.
|
|
35
|
-
|
|
36
|
-
self.
|
|
37
|
-
self.
|
|
38
|
-
self.
|
|
39
|
-
|
|
40
|
-
self.
|
|
41
|
-
self.
|
|
42
|
-
self.
|
|
43
|
-
self.
|
|
44
|
-
|
|
45
|
-
self.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
self.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
self.
|
|
61
|
-
|
|
62
|
-
self.
|
|
63
|
-
|
|
64
|
-
self.
|
|
65
|
-
self.
|
|
66
|
-
|
|
67
|
-
self.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
self
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
src,
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
check_file_result =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
check_file_result
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
self.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import copy
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
|
5
|
+
|
|
6
|
+
import anyio
|
|
7
|
+
from telegram import Sticker
|
|
8
|
+
|
|
9
|
+
from sticker_convert.auth.telegram_api import BotAPI, TelegramAPI, TelegramSticker, TelethonAPI
|
|
10
|
+
from sticker_convert.converter import StickerConvert
|
|
11
|
+
from sticker_convert.job_option import CompOption, CredOption, OutputOption
|
|
12
|
+
from sticker_convert.uploaders.upload_base import UploadBase, get_msg_emoji_txt_required
|
|
13
|
+
from sticker_convert.utils.callback import CallbackProtocol, CallbackReturn
|
|
14
|
+
from sticker_convert.utils.emoji import extract_emojis
|
|
15
|
+
from sticker_convert.utils.files.metadata_handler import MetadataHandler
|
|
16
|
+
from sticker_convert.utils.media.codec_info import CodecInfo
|
|
17
|
+
from sticker_convert.utils.media.format_verify import FormatVerify
|
|
18
|
+
from sticker_convert.utils.translate import I
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class UploadTelegram(UploadBase):
|
|
22
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
23
|
+
self.MSG_ASK_DEL_EXIST_PACK = I(
|
|
24
|
+
"Warning: Pack {} already exists.\n"
|
|
25
|
+
"Delete all stickers in pack?\n"
|
|
26
|
+
"Note: After recreating set, please wait for about 3 minutes for the set to reappear."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
super().__init__(*args, **kwargs)
|
|
30
|
+
|
|
31
|
+
self.base_spec.size_max_img = 512000
|
|
32
|
+
self.base_spec.size_max_vid = 256000
|
|
33
|
+
self.base_spec.duration_max = 3000
|
|
34
|
+
self.base_spec.set_res(512)
|
|
35
|
+
|
|
36
|
+
self.png_spec = copy.deepcopy(self.base_spec)
|
|
37
|
+
self.png_spec.set_format((".png",))
|
|
38
|
+
self.png_spec.animated = False
|
|
39
|
+
|
|
40
|
+
self.tgs_spec = copy.deepcopy(self.base_spec)
|
|
41
|
+
self.tgs_spec.set_format((".tgs",))
|
|
42
|
+
self.tgs_spec.fps_min = 60
|
|
43
|
+
self.tgs_spec.fps_max = 60
|
|
44
|
+
self.tgs_spec.size_max_img = 64000
|
|
45
|
+
self.tgs_spec.size_max_vid = 64000
|
|
46
|
+
|
|
47
|
+
self.webm_spec = copy.deepcopy(self.base_spec)
|
|
48
|
+
self.webm_spec.set_format((".webm",))
|
|
49
|
+
self.webm_spec.fps_max = 30
|
|
50
|
+
self.webm_spec.animated = None if self.opt_comp.fake_vid else True
|
|
51
|
+
|
|
52
|
+
self.opt_comp_merged = copy.deepcopy(self.opt_comp)
|
|
53
|
+
self.opt_comp_merged.merge(self.base_spec)
|
|
54
|
+
|
|
55
|
+
base_cover_spec = CompOption(
|
|
56
|
+
size_max_img=128000, size_max_vid=32000, duration_max=3000
|
|
57
|
+
)
|
|
58
|
+
base_cover_spec.set_res(100)
|
|
59
|
+
|
|
60
|
+
self.png_cover_spec = copy.deepcopy(base_cover_spec)
|
|
61
|
+
self.png_cover_spec.set_format((".png",))
|
|
62
|
+
self.png_cover_spec.animated = False
|
|
63
|
+
|
|
64
|
+
self.tgs_cover_spec = copy.deepcopy(base_cover_spec)
|
|
65
|
+
self.tgs_cover_spec.set_format((".tgs",))
|
|
66
|
+
self.tgs_cover_spec.fps_min = 60
|
|
67
|
+
self.tgs_cover_spec.fps_max = 60
|
|
68
|
+
|
|
69
|
+
self.webm_cover_spec = copy.deepcopy(base_cover_spec)
|
|
70
|
+
self.webm_cover_spec.set_format((".webm",))
|
|
71
|
+
self.webm_cover_spec.fps_max = 30
|
|
72
|
+
self.webm_cover_spec.animated = True
|
|
73
|
+
|
|
74
|
+
self.opt_comp_cover_merged = copy.deepcopy(self.opt_comp)
|
|
75
|
+
self.opt_comp_cover_merged.merge(self.base_spec)
|
|
76
|
+
|
|
77
|
+
async def upload_pack(
|
|
78
|
+
self, pack_title: str, stickers: List[Path], emoji_dict: Dict[str, str]
|
|
79
|
+
) -> Tuple[Optional[str], int, int]:
|
|
80
|
+
tg_api: TelegramAPI
|
|
81
|
+
if self.opt_output.option.endswith("telethon"):
|
|
82
|
+
tg_api = TelethonAPI()
|
|
83
|
+
else:
|
|
84
|
+
tg_api = BotAPI()
|
|
85
|
+
|
|
86
|
+
is_emoji = False
|
|
87
|
+
if "emoji" in self.opt_output.option:
|
|
88
|
+
is_emoji = True
|
|
89
|
+
|
|
90
|
+
success = await tg_api.setup(self.opt_cred, True, self.cb, self.cb_return)
|
|
91
|
+
if success is False:
|
|
92
|
+
self.cb.put(I("Download failed: Invalid credentials"))
|
|
93
|
+
return None, len(stickers), 0
|
|
94
|
+
|
|
95
|
+
pack_short_name = await tg_api.set_upload_pack_short_name(pack_title)
|
|
96
|
+
await tg_api.set_upload_pack_type(is_emoji)
|
|
97
|
+
pack_exist = await tg_api.check_pack_exist()
|
|
98
|
+
if pack_exist:
|
|
99
|
+
self.cb.put(
|
|
100
|
+
(
|
|
101
|
+
"ask_bool",
|
|
102
|
+
(self.MSG_ASK_DEL_EXIST_PACK.format(pack_short_name),),
|
|
103
|
+
None,
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
if self.cb_return:
|
|
107
|
+
response = self.cb_return.get_response()
|
|
108
|
+
else:
|
|
109
|
+
response = False
|
|
110
|
+
|
|
111
|
+
if response is True:
|
|
112
|
+
self.cb.put(
|
|
113
|
+
I("Deleting all stickers from pack {}").format(pack_short_name)
|
|
114
|
+
)
|
|
115
|
+
await tg_api.pack_del()
|
|
116
|
+
pack_exist = False
|
|
117
|
+
else:
|
|
118
|
+
self.cb.put(I("Not deleting existing pack {}").format(pack_short_name))
|
|
119
|
+
|
|
120
|
+
if self.opt_output.option == "telegram_emoji":
|
|
121
|
+
sticker_type = Sticker.CUSTOM_EMOJI
|
|
122
|
+
else:
|
|
123
|
+
sticker_type = Sticker.REGULAR
|
|
124
|
+
|
|
125
|
+
stickers_list: List[TelegramSticker] = []
|
|
126
|
+
sticker_format = None
|
|
127
|
+
for src in stickers:
|
|
128
|
+
self.cb.put(I("Verifying {} for uploading to telegram").format(src))
|
|
129
|
+
|
|
130
|
+
emoji = extract_emojis(emoji_dict.get(Path(src).stem, ""))
|
|
131
|
+
if emoji == "":
|
|
132
|
+
self.cb.put(
|
|
133
|
+
I(
|
|
134
|
+
"Warning: Cannot find emoji for file {}, using default emoji..."
|
|
135
|
+
).format(Path(src).name)
|
|
136
|
+
)
|
|
137
|
+
emoji = self.opt_comp.default_emoji
|
|
138
|
+
|
|
139
|
+
if len(emoji) > 20:
|
|
140
|
+
self.cb.put(
|
|
141
|
+
I(
|
|
142
|
+
"Warning: {emoji} emoji for file {file}, exceeding limit of 20, keep first 20 only..."
|
|
143
|
+
).format(emoji=len(emoji), file=Path(src).name)
|
|
144
|
+
)
|
|
145
|
+
emoji_list = [*emoji][:20]
|
|
146
|
+
|
|
147
|
+
ext = Path(src).suffix
|
|
148
|
+
if ext == ".tgs":
|
|
149
|
+
spec_choice = self.tgs_spec
|
|
150
|
+
sticker_format = "animated"
|
|
151
|
+
elif ext == ".webm":
|
|
152
|
+
spec_choice = self.webm_spec
|
|
153
|
+
sticker_format = "video"
|
|
154
|
+
else:
|
|
155
|
+
ext = ".png"
|
|
156
|
+
spec_choice = self.png_spec
|
|
157
|
+
sticker_format = "static"
|
|
158
|
+
|
|
159
|
+
if self.opt_output.option == "telegram_emoji":
|
|
160
|
+
spec_choice.set_res(100)
|
|
161
|
+
|
|
162
|
+
file_info = CodecInfo(src)
|
|
163
|
+
check_file_result = (
|
|
164
|
+
FormatVerify.check_file_fps(
|
|
165
|
+
src, fps=spec_choice.get_fps(), file_info=file_info
|
|
166
|
+
)
|
|
167
|
+
and FormatVerify.check_file_duration(
|
|
168
|
+
src, duration=spec_choice.get_duration(), file_info=file_info
|
|
169
|
+
)
|
|
170
|
+
and FormatVerify.check_file_size(
|
|
171
|
+
src, size=spec_choice.get_size_max(), file_info=file_info
|
|
172
|
+
)
|
|
173
|
+
and FormatVerify.check_format(
|
|
174
|
+
src, fmt=spec_choice.get_format(), file_info=file_info
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
if self.opt_output.option == "telegram":
|
|
178
|
+
if sticker_format == "animated":
|
|
179
|
+
check_file_result = (
|
|
180
|
+
check_file_result
|
|
181
|
+
and file_info.res[0] == 512
|
|
182
|
+
and file_info.res[1] == 512
|
|
183
|
+
)
|
|
184
|
+
else:
|
|
185
|
+
# For video and static stickers (Not animated)
|
|
186
|
+
# Allow file with one of the dimension = 512 but another <512
|
|
187
|
+
# https://core.telegram.org/stickers#video-requirements
|
|
188
|
+
check_file_result = check_file_result and (
|
|
189
|
+
file_info.res[0] == 512 or file_info.res[1] == 512
|
|
190
|
+
)
|
|
191
|
+
check_file_result = check_file_result and (
|
|
192
|
+
file_info.res[0] <= 512 and file_info.res[1] <= 512
|
|
193
|
+
)
|
|
194
|
+
else:
|
|
195
|
+
# telegram_emoji
|
|
196
|
+
check_file_result = (
|
|
197
|
+
check_file_result
|
|
198
|
+
and file_info.res[0] == 100
|
|
199
|
+
and file_info.res[1] == 100
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
if sticker_format == "static":
|
|
203
|
+
# It is important to check if webp and png are static only
|
|
204
|
+
check_file_result = check_file_result and FormatVerify.check_animated(
|
|
205
|
+
src, animated=spec_choice.animated, file_info=file_info
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
if check_file_result:
|
|
209
|
+
with open(src, "rb") as f:
|
|
210
|
+
sticker_bytes = f.read()
|
|
211
|
+
else:
|
|
212
|
+
_, _, convert_result, _ = StickerConvert.convert(
|
|
213
|
+
Path(src),
|
|
214
|
+
Path(f"bytes{ext}"),
|
|
215
|
+
self.opt_comp_merged,
|
|
216
|
+
self.cb,
|
|
217
|
+
self.cb_return,
|
|
218
|
+
)
|
|
219
|
+
sticker_bytes = cast(bytes, convert_result)
|
|
220
|
+
|
|
221
|
+
stickers_list.append((src, sticker_bytes, emoji_list, sticker_format))
|
|
222
|
+
|
|
223
|
+
if pack_exist is False:
|
|
224
|
+
stickers_total, stickers_ok = await tg_api.pack_new(
|
|
225
|
+
stickers_list, sticker_type
|
|
226
|
+
)
|
|
227
|
+
pack_exist = True
|
|
228
|
+
else:
|
|
229
|
+
stickers_total, stickers_ok = await tg_api.pack_add(
|
|
230
|
+
stickers_list, sticker_type
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
cover_path = MetadataHandler.get_cover(self.opt_output.dir)
|
|
234
|
+
if cover_path:
|
|
235
|
+
thumbnail_bytes: Union[None, bytes, Path] = None
|
|
236
|
+
cover_ext = Path(cover_path).suffix
|
|
237
|
+
|
|
238
|
+
if cover_ext == ".tgs":
|
|
239
|
+
thumbnail_format = "animated"
|
|
240
|
+
cover_spec_choice = self.tgs_cover_spec
|
|
241
|
+
elif cover_ext == ".webm":
|
|
242
|
+
thumbnail_format = "video"
|
|
243
|
+
cover_spec_choice = self.webm_cover_spec
|
|
244
|
+
else:
|
|
245
|
+
cover_ext = ".png"
|
|
246
|
+
thumbnail_format = "static"
|
|
247
|
+
cover_spec_choice = self.png_cover_spec
|
|
248
|
+
|
|
249
|
+
if FormatVerify.check_file(cover_path, spec=cover_spec_choice):
|
|
250
|
+
with open(cover_path, "rb") as f:
|
|
251
|
+
thumbnail_bytes = f.read()
|
|
252
|
+
else:
|
|
253
|
+
_, _, thumbnail_bytes, _ = cast(
|
|
254
|
+
Tuple[Any, Any, bytes, Any],
|
|
255
|
+
StickerConvert.convert(
|
|
256
|
+
cover_path,
|
|
257
|
+
Path(f"bytes{cover_ext}"),
|
|
258
|
+
self.opt_comp_cover_merged,
|
|
259
|
+
self.cb,
|
|
260
|
+
self.cb_return,
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
await tg_api.pack_thumbnail(
|
|
265
|
+
(cover_path, thumbnail_bytes, [], thumbnail_format)
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
self.cb.put(I("Finish uploading {}").format(pack_short_name))
|
|
269
|
+
await tg_api.exit()
|
|
270
|
+
return await tg_api.get_pack_url(), stickers_total, stickers_ok
|
|
271
|
+
|
|
272
|
+
def upload_stickers_telegram(self) -> Tuple[int, int, List[str]]:
|
|
273
|
+
urls: List[str] = []
|
|
274
|
+
|
|
275
|
+
title, _, emoji_dict = MetadataHandler.get_metadata(
|
|
276
|
+
self.opt_output.dir,
|
|
277
|
+
title=self.opt_output.title,
|
|
278
|
+
author=self.opt_output.author,
|
|
279
|
+
)
|
|
280
|
+
if title is None:
|
|
281
|
+
raise TypeError(I("title cannot be {}").format(title))
|
|
282
|
+
if emoji_dict is None:
|
|
283
|
+
MetadataHandler.generate_emoji_file(
|
|
284
|
+
directory=self.opt_output.dir, default_emoji=self.opt_comp.default_emoji
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
self.cb.put(
|
|
288
|
+
(
|
|
289
|
+
"msg_block",
|
|
290
|
+
(
|
|
291
|
+
get_msg_emoji_txt_required().format(
|
|
292
|
+
self.opt_output.dir, self.opt_comp.default_emoji
|
|
293
|
+
),
|
|
294
|
+
),
|
|
295
|
+
None,
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
if self.cb_return:
|
|
299
|
+
self.cb_return.get_response()
|
|
300
|
+
|
|
301
|
+
title, _, emoji_dict = MetadataHandler.get_metadata(
|
|
302
|
+
self.opt_output.dir,
|
|
303
|
+
title=self.opt_output.title,
|
|
304
|
+
author=self.opt_output.author,
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
assert title is not None
|
|
308
|
+
assert emoji_dict is not None
|
|
309
|
+
|
|
310
|
+
if self.opt_output.option == "telegram_emoji":
|
|
311
|
+
file_per_pack = 200
|
|
312
|
+
else:
|
|
313
|
+
file_per_pack = 120
|
|
314
|
+
|
|
315
|
+
packs = MetadataHandler.split_sticker_packs(
|
|
316
|
+
self.opt_output.dir,
|
|
317
|
+
title=title,
|
|
318
|
+
file_per_anim_pack=file_per_pack,
|
|
319
|
+
file_per_image_pack=file_per_pack,
|
|
320
|
+
separate_image_anim=not self.opt_comp.fake_vid,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
stickers_total = 0
|
|
324
|
+
stickers_ok = 0
|
|
325
|
+
for pack_title, stickers in packs.items():
|
|
326
|
+
self.cb.put(I("Uploading pack {}").format(pack_title))
|
|
327
|
+
result, stickers_total_pack, stickers_ok_pack = anyio.run(
|
|
328
|
+
self.upload_pack, pack_title, stickers, emoji_dict
|
|
329
|
+
)
|
|
330
|
+
if result:
|
|
331
|
+
self.cb.put((result))
|
|
332
|
+
urls.append(result)
|
|
333
|
+
stickers_total += stickers_total_pack
|
|
334
|
+
stickers_ok += stickers_ok_pack
|
|
335
|
+
|
|
336
|
+
return stickers_ok, stickers_total, urls
|
|
337
|
+
|
|
338
|
+
@staticmethod
|
|
339
|
+
def start(
|
|
340
|
+
opt_output: OutputOption,
|
|
341
|
+
opt_comp: CompOption,
|
|
342
|
+
opt_cred: CredOption,
|
|
343
|
+
cb: CallbackProtocol,
|
|
344
|
+
cb_return: CallbackReturn,
|
|
345
|
+
) -> Tuple[int, int, List[str]]:
|
|
346
|
+
exporter = UploadTelegram(
|
|
347
|
+
opt_output,
|
|
348
|
+
opt_comp,
|
|
349
|
+
opt_cred,
|
|
350
|
+
cb,
|
|
351
|
+
cb_return,
|
|
352
|
+
)
|
|
353
|
+
return exporter.upload_stickers_telegram()
|