59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
|
#!/usr/bin/env python3
|
|||
|
|
|||
|
from bs4 import BeautifulSoup
|
|||
|
import json
|
|||
|
import os
|
|||
|
import requests
|
|||
|
import sys
|
|||
|
|
|||
|
args = sys.argv[1:]
|
|||
|
|
|||
|
pack = args[0]
|
|||
|
print(f'fetching pack {pack}')
|
|||
|
|
|||
|
try:
|
|||
|
pack = int(pack)
|
|||
|
packurl = f'https://store.line.me/stickershop/product/{pack}/en'
|
|||
|
except ValueError:
|
|||
|
packurl = pack
|
|||
|
|
|||
|
try:
|
|||
|
res = requests.get(packurl)
|
|||
|
except:
|
|||
|
print('> failed:')
|
|||
|
print(res.contenf)
|
|||
|
sys.exit(1)
|
|||
|
|
|||
|
soup = BeautifulSoup(res.text, 'html.parser')
|
|||
|
title = soup.title.text.replace(' – LINE stickers | LINE STORE','')
|
|||
|
author = soup.find('a', class_='mdCMN38Item01Author')
|
|||
|
print(f'> {title}')
|
|||
|
print(f'> {author.text}')
|
|||
|
os.mkdir(title)
|
|||
|
stickers = soup.find_all('li', class_='mdCMN09Li')
|
|||
|
|
|||
|
def progress(cur, total, fname):
|
|||
|
if cur == total:
|
|||
|
end = '\n'
|
|||
|
else:
|
|||
|
end = ''
|
|||
|
print(f'\r[{cur}/{total}] {fname}', end=end)
|
|||
|
|
|||
|
print(f'fetching {len(stickers)} stickers')
|
|||
|
total = len(stickers)
|
|||
|
for i, sticker in enumerate(stickers):
|
|||
|
j = json.loads(sticker['data-preview'])
|
|||
|
id = j['id']
|
|||
|
url = j['staticUrl'].replace(';compress=true','')
|
|||
|
|
|||
|
progress(i+1, total, id)
|
|||
|
img = requests.get(url)
|
|||
|
|
|||
|
if img.ok:
|
|||
|
fname = id + '.png'
|
|||
|
out = os.path.join(title, fname)
|
|||
|
with open(out, 'wb') as f:
|
|||
|
f.write(img.content)
|
|||
|
else:
|
|||
|
print('>> failed: {img.content}')
|