q6 commited on
Commit
7d4b3fb
·
1 Parent(s): 6f595fc
Files changed (2) hide show
  1. API/app.py +17 -17
  2. Client/t2.py +2 -1
API/app.py CHANGED
@@ -7,7 +7,7 @@ import time
7
  import uvicorn
8
  from dotenv import load_dotenv
9
  import os
10
- from aiofiles import open as aio_open
11
  from pydantic import BaseModel
12
  from typing import List, Dict
13
  from zipfile import ZipFile
@@ -19,8 +19,6 @@ class pixifModel(BaseModel):
19
  class PixifDownloadModel(BaseModel):
20
  posts: Dict[str, str]
21
 
22
- os.makedirs('Stash', exist_ok=True)
23
-
24
  env_path = os.path.dirname(os.path.realpath(__file__)) + "/../.env"
25
  # config = dotenv_values(env_path)
26
  # PHPSESSID = config.get("PHPSESSID")
@@ -197,7 +195,7 @@ async def process_post(post_id, session, semaphore):
197
  async with semaphore:
198
  try:
199
  data = await fetch_page(session, f"https://www.pixiv.net/ajax/illust/{post_id}/pages")
200
- image_urls = [page['urls']['original'] for page in data['body'] if 'png' in page['urls']['original']][:12]
201
  for image_url in image_urls:
202
  metadata = await get_exif(image_url, session)
203
  exif_type = determine_exif_type(metadata)
@@ -223,13 +221,9 @@ async def pixif(
223
 
224
  async def download_image(session, post_id, post_url):
225
  url = f"{img_base}{post_url}"
226
- if os.path.exists(f"Stash/{post_id}.png"):
227
- return
228
  async with session.get(url) as response:
229
  content = await response.read()
230
- async with aio_open(f"Stash/{post_id}.png", "wb") as f:
231
- await f.write(content)
232
-
233
 
234
  @app.post("/download")
235
  async def download(
@@ -239,14 +233,20 @@ async def download(
239
 
240
  async with aiohttp.ClientSession(cookies=cookies, headers=headers) as session:
241
  tasks = [download_image(session, post_id, image_url) for post_id, image_url in posts.items()]
242
- await asyncio.gather(*tasks)
243
-
244
- timezip = base26_time()
245
- with ZipFile(f"Stash/{timezip}.zip", "w") as zipf:
246
- for post_id in posts:
247
- zipf.write(f"Stash/{post_id}.png", post_id + ".png")
248
-
249
- return FileResponse(path=f"Stash/{timezip}.zip", media_type="application/zip", filename=f"{timezip}.zip")
 
 
 
 
 
 
250
 
251
  @app.get("/")
252
  async def read_root():
 
7
  import uvicorn
8
  from dotenv import load_dotenv
9
  import os
10
+ import io
11
  from pydantic import BaseModel
12
  from typing import List, Dict
13
  from zipfile import ZipFile
 
19
  class PixifDownloadModel(BaseModel):
20
  posts: Dict[str, str]
21
 
 
 
22
  env_path = os.path.dirname(os.path.realpath(__file__)) + "/../.env"
23
  # config = dotenv_values(env_path)
24
  # PHPSESSID = config.get("PHPSESSID")
 
195
  async with semaphore:
196
  try:
197
  data = await fetch_page(session, f"https://www.pixiv.net/ajax/illust/{post_id}/pages")
198
+ image_urls = [page['urls']['original'] for page in data['body'] if 'png' in page['urls']['original']][:20]
199
  for image_url in image_urls:
200
  metadata = await get_exif(image_url, session)
201
  exif_type = determine_exif_type(metadata)
 
221
 
222
  async def download_image(session, post_id, post_url):
223
  url = f"{img_base}{post_url}"
 
 
224
  async with session.get(url) as response:
225
  content = await response.read()
226
+ return (post_id, content)
 
 
227
 
228
  @app.post("/download")
229
  async def download(
 
233
 
234
  async with aiohttp.ClientSession(cookies=cookies, headers=headers) as session:
235
  tasks = [download_image(session, post_id, image_url) for post_id, image_url in posts.items()]
236
+ images = await asyncio.gather(*tasks)
237
+
238
+ zip_buffer = io.BytesIO()
239
+
240
+ with ZipFile(zip_buffer, "w") as zipf:
241
+ for post_id, image_data in images:
242
+ zipf.writestr(f"{post_id}.png", image_data)
243
+
244
+ zip_buffer.seek(0)
245
+ return FileResponse(
246
+ zip_buffer,
247
+ media_type="application/zip",
248
+ filename=f"X.zip"
249
+ )
250
 
251
  @app.get("/")
252
  async def read_root():
Client/t2.py CHANGED
@@ -9,4 +9,5 @@ db = lmdb.open("db", subdir=True, map_size=1048576)
9
  # view all in db
10
  with db.begin() as txn:
11
  for key, value in txn.cursor():
12
- print(key.decode(), value.decode())
 
 
9
  # view all in db
10
  with db.begin() as txn:
11
  for key, value in txn.cursor():
12
+ if value != b'\x00':
13
+ print(key.decode(), value.decode().split('p')[1])