Skip to content

Commit

Permalink
- Also save static ver for some Line POPUP sticker
Browse files Browse the repository at this point in the history
- Simplify download_line
- Use enumerate in looping with count
  • Loading branch information
laggykiller committed Jan 12, 2024
1 parent ea69466 commit 7f92c99
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
9 changes: 2 additions & 7 deletions src/sticker_convert/downloaders/download_kakao.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,9 @@ def download_static(self, thumbnail_urls: str) -> bool:

targets = []

num = 0
for url in thumbnail_urls:
for num, url in enumerate(thumbnail_urls):
dest = os.path.join(self.out_dir, str(num).zfill(3) + ".png")
targets.append((url, dest))
num += 1

self.download_multiple_files(targets)

Expand All @@ -199,13 +197,12 @@ def download_animated(self, item_code: str) -> bool:
self.cb_msg(f"Cannot download {pack_url}")
return False

num = 0
with zipfile.ZipFile(io.BytesIO(zip_file)) as zf:
self.cb_msg("Unzipping...")
if self.cb_bar:
self.cb_bar(set_progress_mode="determinate", steps=len(zf.namelist()))

for f_path in sorted(zf.namelist()):
for num, f_path in enumerate(sorted(zf.namelist())):
_, ext = os.path.splitext(f_path)

if ext in (".gif", ".webp"):
Expand All @@ -222,8 +219,6 @@ def download_animated(self, item_code: str) -> bool:
if self.cb_bar:
self.cb_bar(update_bar=True)

num += 1

self.cb_msg(f"Finished getting {pack_url}")

return True
Expand Down
47 changes: 19 additions & 28 deletions src/sticker_convert/downloaders/download_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,51 +184,49 @@ def get_pack_url(self) -> str:
pack_url = f'https://stickershop.line-scdn.net/stickershop/v1/product/{self.pack_id}/iphone/[email protected]'

return pack_url

def decompress(self, zf: zipfile.ZipFile, f_path: str, num: int, prefix: str = '', suffix: str = ''):
data = zf.read(f_path)
ext = os.path.splitext(f_path)[-1]
if ext == '.png' and int(self.pack_id) < 775:
data = ApplePngNormalize.normalize(data)
self.cb_msg(f'Read {f_path}')

out_path = os.path.join(self.out_dir, prefix + str(num).zfill(3) + suffix + ext)
with open(out_path, 'wb') as f:
f.write(data)

def decompress_emoticon(self, zip_file: bytes):
num = 0
with zipfile.ZipFile(io.BytesIO(zip_file)) as zf:
self.cb_msg('Unzipping...')

self.cb_bar(set_progress_mode='determinate', steps=len(self.pack_files))
for sticker in self.pack_files:
for num, sticker in enumerate(self.pack_files):
if self.resource_type == 'ANIMATION':
f_path = str(sticker) + '_animation.png'
else:
f_path = str(sticker) + '.png'
data = zf.read(f_path)
self.cb_msg(f'Read {f_path}')

out_path = os.path.join(self.out_dir, str(num).zfill(3) + '.png')
with open(out_path, 'wb') as f:
f.write(data)
self.decompress(zf, f_path, num)

if self.cb_bar:
self.cb_bar(update_bar=True)

num += 1

def decompress_stickers(self, zip_file: bytes):
num = 0
with zipfile.ZipFile(io.BytesIO(zip_file)) as zf:
self.cb_msg('Unzipping...')

self.cb_bar(set_progress_mode='determinate', steps=len(self.pack_files))
for sticker in self.pack_files:
for num, sticker in enumerate(self.pack_files):
if self.resource_type in ('ANIMATION', 'ANIMATION_SOUND'):
f_path = 'animation@2x/' + str(sticker['id']) + '@2x.png'
elif self.resource_type == 'POPUP':
if sticker.get('popup', {}).get('layer') == 'BACKGROUND':
f_path = str(sticker['id']) + '@2x.png'
self.decompress(zf, f_path, num, 'preview-')
f_path = 'popup/' + str(sticker['id']) + '.png'
else:
f_path = str(sticker['id']) + '@2x.png'
data = zf.read(f_path)
if int(self.pack_id) < 775:
data = ApplePngNormalize.normalize(data)
self.cb_msg(f'Read {f_path}')

out_path = os.path.join(self.out_dir, str(num).zfill(3) + '.png')
with open(out_path, 'wb') as f:
f.write(data)
self.decompress(zf, f_path, num)

if self.resource_type == 'PER_STICKER_TEXT':
self.sticker_text_dict[num] = {
Expand All @@ -244,17 +242,10 @@ def decompress_stickers(self, zip_file: bytes):

if self.has_sound:
f_path = 'sound/' + str(sticker['id']) + '.m4a'
data = zf.read(f_path)
self.cb_msg(f'Read {f_path}')

out_path = os.path.join(self.out_dir, str(num).zfill(3) + '.m4a')
with open(out_path, 'wb') as f:
f.write(data)
self.decompress(zf, f_path, num)

if self.cb_bar:
self.cb_bar(update_bar=True)

num += 1

def edit_custom_sticker_text(self):
line_sticker_text_path = os.path.join(self.out_dir, 'line-sticker-text.txt')
Expand Down
4 changes: 1 addition & 3 deletions src/sticker_convert/downloaders/download_telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ async def save_stickers(self) -> bool:
)

emoji_dict = {}
num = 0
for i in sticker_set.stickers:
for num, i in enumerate(sticker_set.stickers):
sticker = await i.get_file(
read_timeout=30,
write_timeout=30,
Expand All @@ -79,7 +78,6 @@ async def save_stickers(self) -> bool:
self.cb_msg(f"Downloaded {f_name}")
if self.cb_bar:
self.cb_bar(update_bar=True)
num += 1

if sticker_set.thumbnail:
cover = await sticker_set.thumbnail.get_file(
Expand Down
5 changes: 2 additions & 3 deletions src/sticker_convert/uploaders/compress_wastickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def compress_wastickers(self) -> list[str]:
)

for pack_title, stickers in packs.items():
num = 0 # Originally the Sticker Maker application name the files with int(time.time())
# Originally the Sticker Maker application name the files with int(time.time())
with CacheStore.get_cache_store(
path=self.opt_comp.cache_dir
) as tempdir:
for src in stickers:
for num, src in enumerate(stickers):
self.cb_msg(f"Verifying {src} for compressing into .wastickers")

if self.fake_vid or CodecInfo.is_anim(src):
Expand All @@ -71,7 +71,6 @@ def compress_wastickers(self) -> list[str]:
ext = ".png"

dst = os.path.join(tempdir, str(num) + ext)
num += 1

if (FormatVerify.check_file(src, spec=self.webp_spec) or
FormatVerify.check_file(src, spec=self.png_spec)):
Expand Down

0 comments on commit 7f92c99

Please sign in to comment.