Back
Browse files- API/app.py +17 -33
API/app.py
CHANGED
|
@@ -189,49 +189,33 @@ def parse_png_metadata(data):
|
|
| 189 |
index += chunk_len + 4
|
| 190 |
return None
|
| 191 |
|
| 192 |
-
async def
|
| 193 |
async with semaphore:
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
@app.post("/pixif")
|
| 204 |
async def pixif(
|
| 205 |
items: pixifModel
|
| 206 |
):
|
| 207 |
post_ids = items.post_ids
|
| 208 |
-
semaphore = asyncio.Semaphore(
|
| 209 |
|
| 210 |
async with aiohttp.ClientSession(cookies=cookies, headers=headers) as session:
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
image_list = []
|
| 215 |
-
for post_id, data in zip(post_ids, pages_results):
|
| 216 |
-
image_urls = [page['urls']['original'] for page in data['body'] if 'png' in page['urls']['original']][:20]
|
| 217 |
-
for image_url in image_urls:
|
| 218 |
-
image_list.append({'post_id': post_id, 'image_url': image_url})
|
| 219 |
-
|
| 220 |
-
image_list.sort(key=lambda x: int(x['post_id']))
|
| 221 |
-
|
| 222 |
-
batch_size = 20
|
| 223 |
-
for i in range(0, len(image_list), batch_size):
|
| 224 |
-
batch = image_list[i:i+batch_size]
|
| 225 |
-
tasks = [process_image(image_dict, session, semaphore) for image_dict in batch]
|
| 226 |
-
results = await asyncio.gather(*tasks)
|
| 227 |
-
for result in results:
|
| 228 |
-
if result:
|
| 229 |
-
post_id = result['post_id']
|
| 230 |
-
image_url = result['image_url']
|
| 231 |
-
image_exifs = {post_id: image_url.replace('https://i.pximg.net/img-original/', '', 1)}
|
| 232 |
-
return image_exifs
|
| 233 |
-
return {}
|
| 234 |
|
|
|
|
|
|
|
| 235 |
|
| 236 |
async def generate_zip(posts, session):
|
| 237 |
zip_buffer = io.BytesIO()
|
|
|
|
| 189 |
index += chunk_len + 4
|
| 190 |
return None
|
| 191 |
|
| 192 |
+
async def process_post(post_id, session, semaphore):
|
| 193 |
async with semaphore:
|
| 194 |
+
try:
|
| 195 |
+
data = await fetch_page(session, f"https://www.pixiv.net/ajax/illust/{post_id}/pages")
|
| 196 |
+
image_urls = [page['urls']['original'] for page in data['body'] if 'png' in page['urls']['original']][:20]
|
| 197 |
+
for image_url in image_urls:
|
| 198 |
+
metadata = await get_exif(image_url, session)
|
| 199 |
+
exif_type = determine_exif_type(metadata)
|
| 200 |
+
if exif_type not in ['photoshop', 'celsys', None]:
|
| 201 |
+
return post_id, image_url
|
| 202 |
+
return post_id, None
|
| 203 |
+
except Exception as e:
|
| 204 |
+
return post_id, None
|
| 205 |
|
| 206 |
@app.post("/pixif")
|
| 207 |
async def pixif(
|
| 208 |
items: pixifModel
|
| 209 |
):
|
| 210 |
post_ids = items.post_ids
|
| 211 |
+
semaphore = asyncio.Semaphore(100)
|
| 212 |
|
| 213 |
async with aiohttp.ClientSession(cookies=cookies, headers=headers) as session:
|
| 214 |
+
tasks = [process_post(post_id, session, semaphore) for post_id in post_ids]
|
| 215 |
+
results = await asyncio.gather(*tasks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
image_exifs = {post_id: image_url.replace('https://i.pximg.net/img-original/', '', 1) for post_id, image_url in results if image_url}
|
| 218 |
+
return image_exifs
|
| 219 |
|
| 220 |
async def generate_zip(posts, session):
|
| 221 |
zip_buffer = io.BytesIO()
|