q6 commited on
Commit
4e1b77d
·
1 Parent(s): 4010c7a
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ *.txt
3
+ db
API/README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: P
3
+ emoji: 🚀
4
+ colorFrom: purple
5
+ colorTo: yellow
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
API/app.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import aiohttp
3
+ import asyncio
4
+ import time
5
+ import uvicorn
6
+ from dotenv import load_dotenv
7
+ import os
8
+ from pydantic import BaseModel
9
+ from typing import List
10
+
11
+ class pixifModel(BaseModel):
12
+ post_ids: List[int]
13
+
14
+ env_path = os.path.dirname(os.path.realpath(__file__)) + "/../.env"
15
+ # config = dotenv_values(env_path)
16
+ # PHPSESSID = config.get("PHPSESSID")
17
+ if os.path.exists(env_path):
18
+ load_dotenv(env_path)
19
+ PHPSESSID = os.getenv("PHPSESSID")
20
+ cookies = {"PHPSESSID": PHPSESSID}
21
+
22
+ headers = {
23
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0",
24
+ 'referer': 'https://www.pixiv.net/',
25
+ }
26
+
27
+ app = FastAPI()
28
+
29
+ async def fetch_page(session, url):
30
+ async with session.get(url) as response:
31
+ data = await response.json()
32
+ return data
33
+
34
+ def base26(n):
35
+ if n == 0:
36
+ return "A"
37
+
38
+ b26 = ""
39
+ while n > 0:
40
+ n, remainder = divmod(n, 26)
41
+ b26 = chr(97 + remainder) + b26
42
+
43
+ return b26
44
+
45
+ def base26_time():
46
+ return base26(int(time.time()))
47
+
48
+ def determine_exif_type(metadata):
49
+ if metadata is None:
50
+ return None
51
+ elif metadata == b'TitleAI generated image':
52
+ return "novelai"
53
+ elif metadata.startswith(b"parameter"):
54
+ return "sd"
55
+ elif b'{"' in metadata:
56
+ return "comfy"
57
+ elif b"Dig" in metadata:
58
+ return "mj"
59
+ elif metadata.startswith(b"SoftwareCelsys"):
60
+ return "celsys"
61
+ else:
62
+ return "photoshop"
63
+
64
+ async def get_exif(url, session):
65
+ start_range = 0
66
+ end_range = 1024
67
+
68
+ headers = {
69
+ "Referer": "https://www.pixiv.net/",
70
+ "Range": f"bytes={start_range}-{end_range}"
71
+ }
72
+
73
+ async with session.get(url, headers=headers) as response:
74
+ data = await response.read()
75
+ return parse_png_metadata(data)
76
+
77
+ def parse_png_metadata(data):
78
+ index = 8
79
+
80
+ while index < len(data):
81
+ if index + 8 > len(data):
82
+ break
83
+ chunk_len = int.from_bytes(data[index:index+4], 'big')
84
+ chunk_type = data[index+4:index+8].decode('ascii')
85
+ index += 8
86
+
87
+ if chunk_type in ['tEXt', 'iTXt']:
88
+ content = data[index:index+chunk_len]
89
+ if chunk_type == 'tEXt':
90
+ return content.replace(b'\0', b'')
91
+ elif chunk_type == 'iTXt':
92
+ return content.strip()
93
+
94
+ index += chunk_len + 4
95
+ return None
96
+
97
+ async def process_post(post_id, session, semaphore):
98
+ async with semaphore:
99
+ try:
100
+ data = await fetch_page(session, f"https://www.pixiv.net/ajax/illust/{post_id}/pages")
101
+ image_urls = [page['urls']['original'] for page in data['body'] if 'png' in page['urls']['original']][:12]
102
+ for image_url in image_urls:
103
+ metadata = await get_exif(image_url, session)
104
+ exif_type = determine_exif_type(metadata)
105
+ if exif_type not in ['photoshop', 'celsys', None]:
106
+ return post_id, image_url
107
+ return post_id, None
108
+ except Exception as e:
109
+ return post_id, None
110
+
111
+ @app.post("/pixif")
112
+ async def pixif(
113
+ items: pixifModel
114
+ ):
115
+ post_ids = items.post_ids
116
+ semaphore = asyncio.Semaphore(100)
117
+
118
+ async with aiohttp.ClientSession(cookies=cookies, headers=headers) as session:
119
+ tasks = [process_post(post_id, session, semaphore) for post_id in post_ids]
120
+ results = await asyncio.gather(*tasks)
121
+
122
+ image_exifs = {post_id: image_url for post_id, image_url in results if image_url}
123
+ return {"image_exifs": image_exifs}
124
+
125
+ @app.get("/")
126
+ async def read_root():
127
+ return {"message": "Hello, World!"}
128
+
129
+ if __name__ == "__main__":
130
+ uvicorn.run(app, host="127.0.0.1", port=7860)
Client/Extract Pixiv/ai_search.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+
4
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
5
+
6
+ input_url = input("Enter the URL: ")
7
+
8
+ pages = 60 // 60
9
+
10
+ params = {
11
+ 'raw': input_url,
12
+ 'pages': pages,
13
+ 'ai_only': True,
14
+ }
15
+
16
+ response = requests.get('http://127.0.0.1:8000/search', params=params)
17
+
18
+ data = response.json()
19
+
20
+ with open(f"../{data['filename']}.txt", "w") as f:
21
+ f.write("\n".join(data['post_ids']))
Client/Extract Pixiv/user.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import re
3
+ import os
4
+
5
+ def main():
6
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
7
+
8
+ inp = input("Enter User IDs (separated by spaces or commas): ")
9
+ user_ids = re.findall(r"\d+", inp)
10
+
11
+ user_ids = [int(uid) for uid in user_ids]
12
+
13
+ response = requests.get('http://127.0.0.1:8000/users', params={'user_ids': user_ids})
14
+ response.raise_for_status()
15
+ data = response.json()
16
+
17
+ for user_data in data:
18
+ if 'error' in user_data:
19
+ print(f"User ID {user_data.get('user_id')} Error: {user_data.get('error')}")
20
+ continue
21
+ filename = user_data['filename']
22
+ post_ids = user_data['post_ids']
23
+ with open(os.path.join("..", filename + '.txt'), "w", encoding='utf-8') as f:
24
+ f.write("\n".join(post_ids))
25
+
26
+ if __name__ == "__main__":
27
+ main()
Client/hunt.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import lmdb
3
+ import requests
4
+
5
+
6
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
7
+
8
+ db = lmdb.open("db", subdir=True, map_size=10485760)
9
+
10
+ valid = [f for f in os.listdir() if f.endswith(".txt")]
11
+ print(valid)
12
+ for idx, file in enumerate(valid):
13
+ print(f"{idx + 1}: {file}")
14
+
15
+ inputs = input("Enter the index of the file: ")
16
+ inputs = inputs.split()
17
+ indexs = []
18
+
19
+ for inp in inputs:
20
+ if inp.isdigit():
21
+ indexs.append(int(inp) - 1)
22
+ elif "-" in inp:
23
+ start, end = map(int, inp.split("-"))
24
+ indexs.extend(range(start - 1, end))
25
+
26
+ for index in indexs:
27
+ with open(valid[index], "r") as f:
28
+ post_ids = [x for x in f.read().split("\n") if x]
29
+
30
+ with db.begin(write=False) as txn:
31
+ post_ids = [post_id for post_id in post_ids if not txn.get(post_id.encode())]
32
+
33
+ data = requests.post('http://127.0.0.1:8000/pixif', json={"post_ids": post_ids}).json()
34
+
35
+ print(data)
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.10-slim
3
+
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+ ENV PATH="/home/user/.local/bin:$PATH"
7
+ ENV PYTHONDONTWRITEBYTECODE=1
8
+ ENV PYTHONUNBUFFERED=1
9
+ WORKDIR /app
10
+
11
+ RUN pip install --no-cache-dir fastapi aiohttp uvicorn python-dotenv pydantic
12
+
13
+ COPY --chown=user ./API /app
14
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: P
3
+ emoji: 🐠
4
+ colorFrom: gray
5
+ colorTo: purple
6
+ sdk: docker
7
+ pinned: false
8
+ app_port: 7860
9
+ ---
10
+
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference