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.
Files changed (93) hide show
  1. sticker_convert/__main__.py +24 -27
  2. sticker_convert/auth/__init__.py +0 -0
  3. sticker_convert/auth/auth_base.py +19 -0
  4. sticker_convert/{utils/auth/get_discord_auth.py → auth/auth_discord.py} +149 -118
  5. sticker_convert/{utils/auth/get_kakao_auth.py → auth/auth_kakao_android_login.py} +331 -330
  6. sticker_convert/auth/auth_kakao_desktop_login.py +327 -0
  7. sticker_convert/{utils/auth/get_kakao_desktop_auth.py → auth/auth_kakao_desktop_memdump.py} +281 -263
  8. sticker_convert/{utils/auth/get_line_auth.py → auth/auth_line.py} +98 -80
  9. sticker_convert/{utils/auth/get_signal_auth.py → auth/auth_signal.py} +139 -135
  10. sticker_convert/auth/auth_telethon.py +161 -0
  11. sticker_convert/{utils/auth/get_viber_auth.py → auth/auth_viber.py} +250 -235
  12. sticker_convert/{utils/auth → auth}/telegram_api.py +736 -675
  13. sticker_convert/cli.py +623 -608
  14. sticker_convert/converter.py +1093 -1084
  15. sticker_convert/definitions.py +4 -0
  16. sticker_convert/downloaders/download_band.py +111 -110
  17. sticker_convert/downloaders/download_base.py +171 -166
  18. sticker_convert/downloaders/download_discord.py +92 -91
  19. sticker_convert/downloaders/download_kakao.py +417 -404
  20. sticker_convert/downloaders/download_line.py +484 -475
  21. sticker_convert/downloaders/download_ogq.py +80 -79
  22. sticker_convert/downloaders/download_signal.py +108 -105
  23. sticker_convert/downloaders/download_telegram.py +56 -55
  24. sticker_convert/downloaders/download_viber.py +121 -120
  25. sticker_convert/gui.py +788 -873
  26. sticker_convert/gui_components/frames/comp_frame.py +180 -166
  27. sticker_convert/gui_components/frames/config_frame.py +156 -113
  28. sticker_convert/gui_components/frames/control_frame.py +32 -30
  29. sticker_convert/gui_components/frames/cred_frame.py +232 -233
  30. sticker_convert/gui_components/frames/input_frame.py +139 -137
  31. sticker_convert/gui_components/frames/output_frame.py +112 -110
  32. sticker_convert/gui_components/frames/right_clicker.py +25 -23
  33. sticker_convert/gui_components/windows/advanced_compression_window.py +757 -757
  34. sticker_convert/gui_components/windows/base_window.py +7 -2
  35. sticker_convert/gui_components/windows/discord_get_auth_window.py +79 -82
  36. sticker_convert/gui_components/windows/kakao_get_auth_window.py +511 -321
  37. sticker_convert/gui_components/windows/line_get_auth_window.py +94 -102
  38. sticker_convert/gui_components/windows/signal_get_auth_window.py +84 -89
  39. sticker_convert/gui_components/windows/viber_get_auth_window.py +168 -168
  40. sticker_convert/ios-message-stickers-template/.github/FUNDING.yml +3 -3
  41. sticker_convert/ios-message-stickers-template/README.md +10 -10
  42. sticker_convert/ios-message-stickers-template/stickers/Info.plist +43 -43
  43. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Info.plist +31 -31
  44. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Contents.json +6 -6
  45. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Contents.json +20 -20
  46. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Sticker 1.sticker/Contents.json +9 -9
  47. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Sticker 2.sticker/Contents.json +9 -9
  48. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Sticker 3.sticker/Contents.json +9 -9
  49. sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset/Contents.json +91 -91
  50. sticker_convert/ios-message-stickers-template/stickers.xcodeproj/project.pbxproj +364 -364
  51. sticker_convert/ios-message-stickers-template/stickers.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -7
  52. sticker_convert/ios-message-stickers-template/stickers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  53. sticker_convert/ios-message-stickers-template/stickers.xcodeproj/xcuserdata/niklaspeterson.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  54. sticker_convert/job.py +166 -130
  55. sticker_convert/job_option.py +1 -0
  56. sticker_convert/locales/en_US/LC_MESSAGES/base.mo +0 -0
  57. sticker_convert/locales/ja_JP/LC_MESSAGES/base.mo +0 -0
  58. sticker_convert/locales/zh_CN/LC_MESSAGES/base.mo +0 -0
  59. sticker_convert/locales/zh_TW/LC_MESSAGES/base.mo +0 -0
  60. sticker_convert/py.typed +0 -0
  61. sticker_convert/resources/NotoColorEmoji.ttf +0 -0
  62. sticker_convert/resources/help.ja_JP.json +88 -0
  63. sticker_convert/resources/help.json +10 -7
  64. sticker_convert/resources/help.zh_CN.json +88 -0
  65. sticker_convert/resources/help.zh_TW.json +88 -0
  66. sticker_convert/resources/input.ja_JP.json +74 -0
  67. sticker_convert/resources/input.json +121 -121
  68. sticker_convert/resources/input.zh_CN.json +74 -0
  69. sticker_convert/resources/input.zh_TW.json +74 -0
  70. sticker_convert/resources/output.ja_JP.json +38 -0
  71. sticker_convert/resources/output.zh_CN.json +38 -0
  72. sticker_convert/resources/output.zh_TW.json +38 -0
  73. sticker_convert/uploaders/compress_wastickers.py +186 -177
  74. sticker_convert/uploaders/upload_base.py +44 -35
  75. sticker_convert/uploaders/upload_signal.py +218 -203
  76. sticker_convert/uploaders/upload_telegram.py +353 -338
  77. sticker_convert/uploaders/upload_viber.py +178 -169
  78. sticker_convert/uploaders/xcode_imessage.py +295 -286
  79. sticker_convert/utils/callback.py +238 -6
  80. sticker_convert/utils/emoji.py +16 -4
  81. sticker_convert/utils/files/json_resources_loader.py +24 -19
  82. sticker_convert/utils/files/metadata_handler.py +3 -3
  83. sticker_convert/utils/translate.py +108 -0
  84. sticker_convert/utils/url_detect.py +40 -37
  85. sticker_convert/version.py +1 -1
  86. {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/METADATA +89 -74
  87. {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/RECORD +91 -74
  88. sticker_convert/utils/auth/telethon_setup.py +0 -97
  89. sticker_convert/utils/singletons.py +0 -18
  90. {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/WHEEL +0 -0
  91. {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/entry_points.txt +0 -0
  92. {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/licenses/LICENSE +0 -0
  93. {sticker_convert-2.13.3.0.dist-info → sticker_convert-2.17.0.0.dist-info}/top_level.txt +0 -0
@@ -1,286 +1,295 @@
1
- #!/usr/bin/env python3
2
- import copy
3
- import json
4
- import os
5
- import plistlib
6
- import shutil
7
- import zipfile
8
- from pathlib import Path
9
- from typing import Any, Dict, List, Tuple
10
-
11
- from sticker_convert.converter import StickerConvert
12
- from sticker_convert.definitions import ROOT_DIR
13
- from sticker_convert.job_option import CompOption, CredOption, OutputOption
14
- from sticker_convert.uploaders.upload_base import UploadBase
15
- from sticker_convert.utils.callback import CallbackProtocol, CallbackReturn
16
- from sticker_convert.utils.files.metadata_handler import XCODE_IMESSAGE_ICONSET, MetadataHandler
17
- from sticker_convert.utils.files.sanitize_filename import sanitize_filename
18
- from sticker_convert.utils.media.codec_info import CodecInfo
19
- from sticker_convert.utils.media.format_verify import FormatVerify
20
-
21
-
22
- class XcodeImessage(UploadBase):
23
- def __init__(self, *args: Any, **kwargs: Any) -> None:
24
- super().__init__(*args, **kwargs)
25
- self.base_spec.set_size_max(500000)
26
- self.base_spec.set_res(300)
27
- self.base_spec.set_format(("png", ".apng", ".gif", ".jpeg", "jpg"))
28
-
29
- self.small_spec = copy.deepcopy(self.base_spec)
30
-
31
- self.medium_spec = copy.deepcopy(self.base_spec)
32
- self.medium_spec.set_res(408)
33
-
34
- self.large_spec = copy.deepcopy(self.base_spec)
35
- self.large_spec.set_res(618)
36
-
37
- def create_imessage_xcode(self) -> Tuple[int, int, List[str]]:
38
- urls: List[str] = []
39
- title, author, _ = MetadataHandler.get_metadata(
40
- self.opt_output.dir,
41
- title=self.opt_output.title,
42
- author=self.opt_output.author,
43
- )
44
- if not author:
45
- self.cb.put("author is required for creating Xcode iMessage sticker pack")
46
- return 0, 0, urls
47
- if not title:
48
- self.cb.put("title is required for creating Xcode iMessage sticker pack")
49
- return 0, 0, urls
50
-
51
- author = author.replace(" ", "_")
52
- title = title.replace(" ", "_")
53
- packs = MetadataHandler.split_sticker_packs(
54
- self.opt_output.dir,
55
- title=title,
56
- file_per_pack=100,
57
- separate_image_anim=False,
58
- )
59
-
60
- res_choice = None
61
- spec_choice = None
62
- opt_comp_merged = copy.deepcopy(self.opt_comp)
63
-
64
- stickers_total = 0
65
- for pack_title, stickers in packs.items():
66
- pack_title = sanitize_filename(pack_title)
67
-
68
- for src in stickers:
69
- self.cb.put(f"Verifying {src} for creating Xcode iMessage sticker pack")
70
-
71
- fpath = Path(self.opt_output.dir, src)
72
-
73
- if res_choice is None:
74
- res_choice, _ = CodecInfo.get_file_res(fpath)
75
-
76
- if res_choice == 618:
77
- spec_choice = self.large_spec
78
- elif res_choice == 408:
79
- spec_choice = self.medium_spec
80
- else:
81
- # res_choice == 300
82
- spec_choice = self.small_spec
83
-
84
- opt_comp_merged.merge(spec_choice)
85
-
86
- assert spec_choice
87
- if not FormatVerify.check_file(src, spec=spec_choice):
88
- StickerConvert.convert(
89
- fpath, fpath, opt_comp_merged, self.cb, self.cb_return
90
- )
91
- stickers_total += 1
92
-
93
- self.add_metadata(author, pack_title)
94
- self.create_xcode_proj(author, pack_title)
95
-
96
- result = Path(self.opt_output.dir / pack_title).as_posix()
97
- self.cb.put(result)
98
- urls.append(result)
99
-
100
- return stickers_total, stickers_total, urls
101
-
102
- def add_metadata(self, author: str, title: str) -> None:
103
- first_image_path = Path(
104
- self.opt_output.dir,
105
- [
106
- i
107
- for i in sorted(self.opt_output.dir.iterdir())
108
- if (self.opt_output.dir / i).is_file() and i.suffix == ".png"
109
- ][0],
110
- )
111
- cover_path = MetadataHandler.get_cover(self.opt_output.dir)
112
- if cover_path:
113
- icon_source = cover_path
114
- else:
115
- icon_source = first_image_path
116
-
117
- for icon, res in XCODE_IMESSAGE_ICONSET.items():
118
- spec_cover = CompOption()
119
- spec_cover.set_res_w(res[0])
120
- spec_cover.set_res_h(res[1])
121
- spec_cover.set_fps(0)
122
-
123
- icon_path = self.opt_output.dir / icon
124
- if Path(icon) in list(
125
- self.opt_output.dir.iterdir()
126
- ) and not FormatVerify.check_file(icon_path, spec=spec_cover):
127
- StickerConvert.convert(
128
- icon_path, icon_path, spec_cover, self.cb, self.cb_return
129
- )
130
- else:
131
- StickerConvert.convert(
132
- icon_source, icon_path, spec_cover, self.cb, self.cb_return
133
- )
134
-
135
- MetadataHandler.set_metadata(self.opt_output.dir, author=author, title=title)
136
-
137
- def create_xcode_proj(self, author: str, title: str) -> None:
138
- pack_path = self.opt_output.dir / title
139
- if (ROOT_DIR / "ios-message-stickers-template.zip").is_file():
140
- with zipfile.ZipFile(
141
- ROOT_DIR / "ios-message-stickers-template.zip", "r"
142
- ) as f:
143
- f.extractall(pack_path)
144
- elif (ROOT_DIR / "ios-message-stickers-template").is_dir():
145
- shutil.copytree(ROOT_DIR / "ios-message-stickers-template", pack_path)
146
- else:
147
- self.cb.put(
148
- "Failed to create Xcode project: ios-message-stickers-template not found"
149
- )
150
-
151
- os.remove(pack_path / "README.md")
152
- shutil.rmtree(
153
- pack_path / "stickers.xcodeproj/project.xcworkspace",
154
- ignore_errors=True,
155
- )
156
- shutil.rmtree(pack_path / "stickers.xcodeproj/xcuserdata", ignore_errors=True)
157
-
158
- with open(
159
- pack_path / "stickers.xcodeproj/project.pbxproj",
160
- encoding="utf-8",
161
- ) as f:
162
- pbxproj_data = f.read()
163
-
164
- pbxproj_data = pbxproj_data.replace(
165
- "stickers StickerPackExtension", f"{title} StickerPackExtension"
166
- )
167
- pbxproj_data = pbxproj_data.replace("stickers.app", f"{title}.app")
168
- pbxproj_data = pbxproj_data.replace("/* stickers */", f"/* {title} */")
169
- pbxproj_data = pbxproj_data.replace("name = stickers", f"name = {title}")
170
- pbxproj_data = pbxproj_data.replace(
171
- "productName = stickers", f"productName = {title}"
172
- )
173
- pbxproj_data = pbxproj_data.replace(
174
- '/* Build configuration list for PBXProject "stickers" */',
175
- f'/* Build configuration list for PBXProject "{title}" */',
176
- )
177
- pbxproj_data = pbxproj_data.replace(
178
- '/* Build configuration list for PBXNativeTarget "stickers StickerPackExtension" */',
179
- f'/* Build configuration list for PBXNativeTarget "{title} StickerPackExtension" */',
180
- )
181
- pbxproj_data = pbxproj_data.replace(
182
- '/* Build configuration list for PBXNativeTarget "stickers" */',
183
- f'/* Build configuration list for PBXNativeTarget "{title}" */',
184
- )
185
- pbxproj_data = pbxproj_data.replace("com.niklaspeterson", f"com.{author}")
186
- pbxproj_data = pbxproj_data.replace(
187
- "stickers/Info.plist", f"{title}/Info.plist"
188
- )
189
-
190
- with open(
191
- pack_path / "stickers.xcodeproj/project.pbxproj",
192
- "w+",
193
- encoding="utf-8",
194
- ) as f:
195
- f.write(pbxproj_data)
196
-
197
- # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack
198
- stickers_path = (
199
- pack_path
200
- / "stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack"
201
- )
202
-
203
- for i in stickers_path.iterdir():
204
- if i.suffix == ".sticker":
205
- shutil.rmtree(stickers_path / i)
206
-
207
- stickers_lst: List[str] = []
208
- for i in sorted(self.opt_output.dir.iterdir()):
209
- if (
210
- CodecInfo.get_file_ext(i) == ".png"
211
- and i.stem != "cover"
212
- and i.name not in XCODE_IMESSAGE_ICONSET
213
- ):
214
- sticker_dir = f"{i.stem}.sticker" # 0.sticker
215
- stickers_lst.append(sticker_dir)
216
- # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/0.sticker
217
- sticker_path = stickers_path / sticker_dir
218
- os.mkdir(sticker_path)
219
- # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/0.sticker/0.png
220
- shutil.copy(self.opt_output.dir / i.name, sticker_path / i.name)
221
-
222
- sticker_json_content = {
223
- "info": {
224
- "author": "xcode",
225
- "version": 1,
226
- },
227
- "properties": {"filename": str(i)},
228
- }
229
-
230
- # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/0.sticker/Contents.json
231
- with open(sticker_path / "Contents.json", "w+", encoding="utf-8") as f:
232
- json.dump(sticker_json_content, f, indent=2)
233
-
234
- # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Contents.json
235
- with open(stickers_path / "Contents.json", encoding="utf-8") as f:
236
- stickerpack_json_content: Dict[str, List[Dict[str, str]]] = json.load(f)
237
-
238
- stickerpack_json_content["stickers"] = []
239
- for sticker in stickers_lst:
240
- stickerpack_json_content["stickers"].append({"filename": sticker})
241
-
242
- with open(stickers_path / "Contents.json", "w+", encoding="utf-8") as f:
243
- json.dump(stickerpack_json_content, f, indent=2)
244
-
245
- # packname StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset
246
- iconset_path = (
247
- pack_path
248
- / "stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset"
249
- )
250
-
251
- for iconfile_name in iconset_path.iterdir():
252
- if Path(iconfile_name).suffix == ".png":
253
- os.remove(iconset_path / iconfile_name)
254
-
255
- icons_lst: List[str] = []
256
- for icon in XCODE_IMESSAGE_ICONSET:
257
- shutil.copy(self.opt_output.dir / icon, iconset_path / icon)
258
- icons_lst.append(icon)
259
-
260
- # packname/Info.plist
261
- plist_path = pack_path / "stickers/Info.plist"
262
- with open(plist_path, "rb") as f:
263
- plist_dict = plistlib.load(f)
264
- plist_dict["CFBundleDisplayName"] = title
265
-
266
- with open(plist_path, "wb+") as f:
267
- plistlib.dump(plist_dict, f)
268
-
269
- Path(pack_path, "stickers").rename(Path(pack_path, title))
270
- Path(pack_path, "stickers StickerPackExtension").rename(
271
- Path(pack_path, f"{title} StickerPackExtension")
272
- )
273
- Path(pack_path, "stickers.xcodeproj").rename(
274
- Path(pack_path, f"{title}.xcodeproj")
275
- )
276
-
277
- @staticmethod
278
- def start(
279
- opt_output: OutputOption,
280
- opt_comp: CompOption,
281
- opt_cred: CredOption,
282
- cb: CallbackProtocol,
283
- cb_return: CallbackReturn,
284
- ) -> Tuple[int, int, List[str]]:
285
- exporter = XcodeImessage(opt_output, opt_comp, opt_cred, cb, cb_return)
286
- return exporter.create_imessage_xcode()
1
+ #!/usr/bin/env python3
2
+ import copy
3
+ import json
4
+ import os
5
+ import plistlib
6
+ import shutil
7
+ import zipfile
8
+ from pathlib import Path
9
+ from typing import Any, Dict, List, Tuple
10
+
11
+ from sticker_convert.converter import StickerConvert
12
+ from sticker_convert.definitions import ROOT_DIR
13
+ from sticker_convert.job_option import CompOption, CredOption, OutputOption
14
+ from sticker_convert.uploaders.upload_base import UploadBase
15
+ from sticker_convert.utils.callback import CallbackProtocol, CallbackReturn
16
+ from sticker_convert.utils.files.metadata_handler import XCODE_IMESSAGE_ICONSET, MetadataHandler
17
+ from sticker_convert.utils.files.sanitize_filename import sanitize_filename
18
+ from sticker_convert.utils.media.codec_info import CodecInfo
19
+ from sticker_convert.utils.media.format_verify import FormatVerify
20
+ from sticker_convert.utils.translate import I
21
+
22
+
23
+ class XcodeImessage(UploadBase):
24
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
25
+ super().__init__(*args, **kwargs)
26
+ self.base_spec.set_size_max(500000)
27
+ self.base_spec.set_res(300)
28
+ self.base_spec.set_format(("png", ".apng", ".gif", ".jpeg", "jpg"))
29
+
30
+ self.small_spec = copy.deepcopy(self.base_spec)
31
+
32
+ self.medium_spec = copy.deepcopy(self.base_spec)
33
+ self.medium_spec.set_res(408)
34
+
35
+ self.large_spec = copy.deepcopy(self.base_spec)
36
+ self.large_spec.set_res(618)
37
+
38
+ def create_imessage_xcode(self) -> Tuple[int, int, List[str]]:
39
+ urls: List[str] = []
40
+ title, author, _ = MetadataHandler.get_metadata(
41
+ self.opt_output.dir,
42
+ title=self.opt_output.title,
43
+ author=self.opt_output.author,
44
+ )
45
+ if not author:
46
+ self.cb.put(
47
+ I("author is required for creating Xcode iMessage sticker pack")
48
+ )
49
+ return 0, 0, urls
50
+ if not title:
51
+ self.cb.put(I("title is required for creating Xcode iMessage sticker pack"))
52
+ return 0, 0, urls
53
+
54
+ author = author.replace(" ", "_")
55
+ title = title.replace(" ", "_")
56
+ packs = MetadataHandler.split_sticker_packs(
57
+ self.opt_output.dir,
58
+ title=title,
59
+ file_per_pack=100,
60
+ separate_image_anim=False,
61
+ )
62
+
63
+ res_choice = None
64
+ spec_choice = None
65
+ opt_comp_merged = copy.deepcopy(self.opt_comp)
66
+
67
+ stickers_total = 0
68
+ for pack_title, stickers in packs.items():
69
+ pack_title = sanitize_filename(pack_title)
70
+
71
+ for src in stickers:
72
+ self.cb.put(
73
+ I("Verifying {} for creating Xcode iMessage sticker pack").format(
74
+ src
75
+ )
76
+ )
77
+
78
+ fpath = Path(self.opt_output.dir, src)
79
+
80
+ if res_choice is None:
81
+ res_choice, _ = CodecInfo.get_file_res(fpath)
82
+
83
+ if res_choice == 618:
84
+ spec_choice = self.large_spec
85
+ elif res_choice == 408:
86
+ spec_choice = self.medium_spec
87
+ else:
88
+ # res_choice == 300
89
+ spec_choice = self.small_spec
90
+
91
+ opt_comp_merged.merge(spec_choice)
92
+
93
+ assert spec_choice
94
+ if not FormatVerify.check_file(src, spec=spec_choice):
95
+ StickerConvert.convert(
96
+ fpath, fpath, opt_comp_merged, self.cb, self.cb_return
97
+ )
98
+ stickers_total += 1
99
+
100
+ self.add_metadata(author, pack_title)
101
+ self.create_xcode_proj(author, pack_title)
102
+
103
+ result = Path(self.opt_output.dir / pack_title).as_posix()
104
+ self.cb.put(result)
105
+ urls.append(result)
106
+
107
+ return stickers_total, stickers_total, urls
108
+
109
+ def add_metadata(self, author: str, title: str) -> None:
110
+ first_image_path = Path(
111
+ self.opt_output.dir,
112
+ [
113
+ i
114
+ for i in sorted(self.opt_output.dir.iterdir())
115
+ if (self.opt_output.dir / i).is_file() and i.suffix == ".png"
116
+ ][0],
117
+ )
118
+ cover_path = MetadataHandler.get_cover(self.opt_output.dir)
119
+ if cover_path:
120
+ icon_source = cover_path
121
+ else:
122
+ icon_source = first_image_path
123
+
124
+ for icon, res in XCODE_IMESSAGE_ICONSET.items():
125
+ spec_cover = CompOption()
126
+ spec_cover.set_res_w(res[0])
127
+ spec_cover.set_res_h(res[1])
128
+ spec_cover.set_fps(0)
129
+
130
+ icon_path = self.opt_output.dir / icon
131
+ if Path(icon) in list(
132
+ self.opt_output.dir.iterdir()
133
+ ) and not FormatVerify.check_file(icon_path, spec=spec_cover):
134
+ StickerConvert.convert(
135
+ icon_path, icon_path, spec_cover, self.cb, self.cb_return
136
+ )
137
+ else:
138
+ StickerConvert.convert(
139
+ icon_source, icon_path, spec_cover, self.cb, self.cb_return
140
+ )
141
+
142
+ MetadataHandler.set_metadata(self.opt_output.dir, author=author, title=title)
143
+
144
+ def create_xcode_proj(self, author: str, title: str) -> None:
145
+ pack_path = self.opt_output.dir / title
146
+ if (ROOT_DIR / "ios-message-stickers-template.zip").is_file():
147
+ with zipfile.ZipFile(
148
+ ROOT_DIR / "ios-message-stickers-template.zip", "r"
149
+ ) as f:
150
+ f.extractall(pack_path)
151
+ elif (ROOT_DIR / "ios-message-stickers-template").is_dir():
152
+ shutil.copytree(ROOT_DIR / "ios-message-stickers-template", pack_path)
153
+ else:
154
+ self.cb.put(
155
+ I(
156
+ "Failed to create Xcode project: ios-message-stickers-template not found"
157
+ )
158
+ )
159
+
160
+ os.remove(pack_path / "README.md")
161
+ shutil.rmtree(
162
+ pack_path / "stickers.xcodeproj/project.xcworkspace",
163
+ ignore_errors=True,
164
+ )
165
+ shutil.rmtree(pack_path / "stickers.xcodeproj/xcuserdata", ignore_errors=True)
166
+
167
+ with open(
168
+ pack_path / "stickers.xcodeproj/project.pbxproj",
169
+ encoding="utf-8",
170
+ ) as f:
171
+ pbxproj_data = f.read()
172
+
173
+ pbxproj_data = pbxproj_data.replace(
174
+ "stickers StickerPackExtension", f"{title} StickerPackExtension"
175
+ )
176
+ pbxproj_data = pbxproj_data.replace("stickers.app", f"{title}.app")
177
+ pbxproj_data = pbxproj_data.replace("/* stickers */", f"/* {title} */")
178
+ pbxproj_data = pbxproj_data.replace("name = stickers", f"name = {title}")
179
+ pbxproj_data = pbxproj_data.replace(
180
+ "productName = stickers", f"productName = {title}"
181
+ )
182
+ pbxproj_data = pbxproj_data.replace(
183
+ '/* Build configuration list for PBXProject "stickers" */',
184
+ f'/* Build configuration list for PBXProject "{title}" */',
185
+ )
186
+ pbxproj_data = pbxproj_data.replace(
187
+ '/* Build configuration list for PBXNativeTarget "stickers StickerPackExtension" */',
188
+ f'/* Build configuration list for PBXNativeTarget "{title} StickerPackExtension" */',
189
+ )
190
+ pbxproj_data = pbxproj_data.replace(
191
+ '/* Build configuration list for PBXNativeTarget "stickers" */',
192
+ f'/* Build configuration list for PBXNativeTarget "{title}" */',
193
+ )
194
+ pbxproj_data = pbxproj_data.replace("com.niklaspeterson", f"com.{author}")
195
+ pbxproj_data = pbxproj_data.replace(
196
+ "stickers/Info.plist", f"{title}/Info.plist"
197
+ )
198
+
199
+ with open(
200
+ pack_path / "stickers.xcodeproj/project.pbxproj",
201
+ "w+",
202
+ encoding="utf-8",
203
+ ) as f:
204
+ f.write(pbxproj_data)
205
+
206
+ # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack
207
+ stickers_path = (
208
+ pack_path
209
+ / "stickers StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack"
210
+ )
211
+
212
+ for i in stickers_path.iterdir():
213
+ if i.suffix == ".sticker":
214
+ shutil.rmtree(stickers_path / i)
215
+
216
+ stickers_lst: List[str] = []
217
+ for i in sorted(self.opt_output.dir.iterdir()):
218
+ if (
219
+ CodecInfo.get_file_ext(i) == ".png"
220
+ and i.stem != "cover"
221
+ and i.name not in XCODE_IMESSAGE_ICONSET
222
+ ):
223
+ sticker_dir = f"{i.stem}.sticker" # 0.sticker
224
+ stickers_lst.append(sticker_dir)
225
+ # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/0.sticker
226
+ sticker_path = stickers_path / sticker_dir
227
+ os.mkdir(sticker_path)
228
+ # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/0.sticker/0.png
229
+ shutil.copy(self.opt_output.dir / i.name, sticker_path / i.name)
230
+
231
+ sticker_json_content = {
232
+ "info": {
233
+ "author": "xcode",
234
+ "version": 1,
235
+ },
236
+ "properties": {"filename": str(i)},
237
+ }
238
+
239
+ # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/0.sticker/Contents.json
240
+ with open(sticker_path / "Contents.json", "w+", encoding="utf-8") as f:
241
+ json.dump(sticker_json_content, f, indent=2)
242
+
243
+ # packname StickerPackExtension/Stickers.xcstickers/Sticker Pack.stickerpack/Contents.json
244
+ with open(stickers_path / "Contents.json", encoding="utf-8") as f:
245
+ stickerpack_json_content: Dict[str, List[Dict[str, str]]] = json.load(f)
246
+
247
+ stickerpack_json_content["stickers"] = []
248
+ for sticker in stickers_lst:
249
+ stickerpack_json_content["stickers"].append({"filename": sticker})
250
+
251
+ with open(stickers_path / "Contents.json", "w+", encoding="utf-8") as f:
252
+ json.dump(stickerpack_json_content, f, indent=2)
253
+
254
+ # packname StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset
255
+ iconset_path = (
256
+ pack_path
257
+ / "stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset"
258
+ )
259
+
260
+ for iconfile_name in iconset_path.iterdir():
261
+ if Path(iconfile_name).suffix == ".png":
262
+ os.remove(iconset_path / iconfile_name)
263
+
264
+ icons_lst: List[str] = []
265
+ for icon in XCODE_IMESSAGE_ICONSET:
266
+ shutil.copy(self.opt_output.dir / icon, iconset_path / icon)
267
+ icons_lst.append(icon)
268
+
269
+ # packname/Info.plist
270
+ plist_path = pack_path / "stickers/Info.plist"
271
+ with open(plist_path, "rb") as f:
272
+ plist_dict = plistlib.load(f)
273
+ plist_dict["CFBundleDisplayName"] = title
274
+
275
+ with open(plist_path, "wb+") as f:
276
+ plistlib.dump(plist_dict, f)
277
+
278
+ Path(pack_path, "stickers").rename(Path(pack_path, title))
279
+ Path(pack_path, "stickers StickerPackExtension").rename(
280
+ Path(pack_path, f"{title} StickerPackExtension")
281
+ )
282
+ Path(pack_path, "stickers.xcodeproj").rename(
283
+ Path(pack_path, f"{title}.xcodeproj")
284
+ )
285
+
286
+ @staticmethod
287
+ def start(
288
+ opt_output: OutputOption,
289
+ opt_comp: CompOption,
290
+ opt_cred: CredOption,
291
+ cb: CallbackProtocol,
292
+ cb_return: CallbackReturn,
293
+ ) -> Tuple[int, int, List[str]]:
294
+ exporter = XcodeImessage(opt_output, opt_comp, opt_cred, cb, cb_return)
295
+ return exporter.create_imessage_xcode()