-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce recreating variables and reading json files
- Loading branch information
1 parent
3ded36d
commit 9ad07c7
Showing
10 changed files
with
167 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Dict, Tuple | ||
import json | ||
from pathlib import Path | ||
|
||
ROOT_DIR = Path(__file__).parents[1] | ||
|
||
def main(): | ||
xcode_imessage_iconset: Dict[str, Tuple[int, int]] = {} | ||
|
||
with open(ROOT_DIR / "src/sticker_convert/ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset/Contents.json") as f: | ||
dict = json.load(f) | ||
|
||
for i in dict["images"]: | ||
filename = i["filename"] | ||
size = i["size"] | ||
size_w = int(size.split("x")[0]) | ||
size_h = int(size.split("x")[1]) | ||
scale = int(i["scale"].replace("x", "")) | ||
size_w_scaled = size_w * scale | ||
size_h_scaled = size_h * scale | ||
|
||
xcode_imessage_iconset[filename] = (size_w_scaled, size_h_scaled) | ||
|
||
print(xcode_imessage_iconset) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import zipfile | ||
from pathlib import Path | ||
from queue import Queue | ||
from typing import Any, Dict, List, Tuple, Union | ||
from typing import Any, Dict, List, Union | ||
|
||
from sticker_convert.converter import CbQueueItemType, StickerConvert | ||
from sticker_convert.definitions import ROOT_DIR | ||
|
@@ -19,65 +19,25 @@ | |
from sticker_convert.utils.media.codec_info import CodecInfo | ||
from sticker_convert.utils.media.format_verify import FormatVerify | ||
|
||
|
||
class XcodeImessageIconset: | ||
iconset: Dict[str, Tuple[int, int]] = {} | ||
|
||
def __init__(self) -> None: | ||
if self.iconset != {}: | ||
return | ||
|
||
if (ROOT_DIR / "ios-message-stickers-template").is_dir(): | ||
with open( | ||
ROOT_DIR | ||
/ "ios-message-stickers-template/stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset/Contents.json" | ||
) as f: | ||
dict = json.load(f) | ||
elif (ROOT_DIR / "ios-message-stickers-template.zip").is_file(): | ||
with zipfile.ZipFile( | ||
(ROOT_DIR / "ios-message-stickers-template.zip"), "r" | ||
) as f: | ||
dict = json.loads( | ||
f.read( | ||
"stickers StickerPackExtension/Stickers.xcstickers/iMessage App Icon.stickersiconset/Contents.json" | ||
).decode() | ||
) | ||
else: | ||
raise FileNotFoundError("ios-message-stickers-template not found") | ||
|
||
for i in dict["images"]: | ||
filename = i["filename"] | ||
size = i["size"] | ||
size_w = int(size.split("x")[0]) | ||
size_h = int(size.split("x")[1]) | ||
scale = int(i["scale"].replace("x", "")) | ||
size_w_scaled = size_w * scale | ||
size_h_scaled = size_h * scale | ||
|
||
self.iconset[filename] = (size_w_scaled, size_h_scaled) | ||
|
||
# self.iconset = { | ||
# 'App-Store-1024x1024pt.png': (1024, 1024), | ||
# '[email protected]': (58, 58), | ||
# '[email protected]': (58, 58), | ||
# '[email protected]': (87, 87), | ||
# '[email protected]': (54, 40), | ||
# '[email protected]': (81, 60), | ||
# '[email protected]': (64, 48), | ||
# '[email protected]': (96, 72), | ||
# 'Messages-App-Store-1024x768pt.png': (1024, 768), | ||
# '[email protected]': (134, 100), | ||
# '[email protected]': (148, 110), | ||
# '[email protected]': (120, 90), | ||
# '[email protected]': (180, 135) | ||
# } | ||
|
||
XCODE_IMESSAGE_ICONSET = { | ||
'App-Store-1024x1024pt.png': (1024, 1024), | ||
'[email protected]': (58, 58), | ||
'[email protected]': (58, 58), | ||
'[email protected]': (87, 87), | ||
'[email protected]': (54, 40), | ||
'[email protected]': (81, 60), | ||
'[email protected]': (64, 48), | ||
'[email protected]': (96, 72), | ||
'Messages-App-Store-1024x768pt.png': (1024, 768), | ||
'[email protected]': (134, 100), | ||
'[email protected]': (148, 110), | ||
'[email protected]': (120, 90), | ||
'[email protected]': (180, 135) | ||
} | ||
|
||
class XcodeImessage(UploadBase): | ||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
super(XcodeImessage, self).__init__(*args, **kwargs) | ||
self.iconset = XcodeImessageIconset().iconset | ||
|
||
self.base_spec.set_size_max(500000) | ||
self.base_spec.set_res(300) | ||
self.base_spec.set_format(("png", ".apng", ".gif", ".jpeg", "jpg")) | ||
|
@@ -169,7 +129,7 @@ def add_metadata(self, author: str, title: str) -> None: | |
else: | ||
icon_source = first_image_path | ||
|
||
for icon, res in self.iconset.items(): | ||
for icon, res in XCODE_IMESSAGE_ICONSET.items(): | ||
spec_cover = CompOption() | ||
spec_cover.set_res_w(res[0]) | ||
spec_cover.set_res_h(res[1]) | ||
|
@@ -264,7 +224,7 @@ def create_xcode_proj(self, author: str, title: str) -> None: | |
if ( | ||
CodecInfo.get_file_ext(i) == ".png" | ||
and i.stem != "cover" | ||
and i.name not in self.iconset | ||
and i.name not in XCODE_IMESSAGE_ICONSET | ||
): | ||
sticker_dir = f"{i.stem}.sticker" # 0.sticker | ||
stickers_lst.append(sticker_dir) | ||
|
@@ -308,7 +268,7 @@ def create_xcode_proj(self, author: str, title: str) -> None: | |
os.remove(iconset_path / iconfile_name) | ||
|
||
icons_lst: List[str] = [] | ||
for icon in self.iconset: | ||
for icon in XCODE_IMESSAGE_ICONSET: | ||
shutil.copy(self.opt_output.dir / icon, iconset_path / icon) | ||
icons_lst.append(icon) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Dict | ||
|
||
from sticker_convert.definitions import ROOT_DIR | ||
from sticker_convert.utils.files.json_manager import JsonManager | ||
|
||
HELP_JSON: Dict[str, Dict[str, str]] = JsonManager.load_json(ROOT_DIR / "resources/help.json") | ||
INPUT_JSON = JsonManager.load_json(ROOT_DIR / "resources/input.json") | ||
COMPRESSION_JSON = JsonManager.load_json(ROOT_DIR / "resources/compression.json") | ||
OUTPUT_JSON = JsonManager.load_json(ROOT_DIR / "resources/output.json") | ||
EMOJI_JSON = JsonManager.load_json(ROOT_DIR / "resources/emoji.json") |
Oops, something went wrong.