Commit ·
139f3ac
0
Parent(s):
Duplicate from CaptiveDreamer/CaraArchive
Browse filesCo-authored-by: Ioannis <CaptiveDreamer@users.noreply.huggingface.co>
- .gitattributes +1 -0
- README.md +92 -0
- catalog.db +3 -0
- tool.py +497 -0
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.db filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CaraArchive Index Dataset
|
| 2 |
+
|
| 3 |
+
### 1) This is an Index Dataset, not an Image dataset
|
| 4 |
+
- This dataset contains **0 image data**.
|
| 5 |
+
- It only contains links to Cara App's CDN and metadata.
|
| 6 |
+
- HuggingFace may load some images in the preview because it detects the CDN links, however those images do not exist as data in this dataset, HF literally just loads them using your own connection as a preview.
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
### How to Query the Database with `tool.py` (make sure `catalog.db` is in the same directory)
|
| 11 |
+
|
| 12 |
+
**To see a clean summary overview of an artist:**
|
| 13 |
+
```bash
|
| 14 |
+
python tool.py --user artist_fc17f3c7 --overview
|
| 15 |
+
# or query by author UUID:
|
| 16 |
+
python tool.py --user fc17f3c7-73ab-4866-8d1a-554da8ea68a9 --overview
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
**To see full breakdown and all image links by artist:**
|
| 20 |
+
```bash
|
| 21 |
+
python tool.py --user artist_fc17f3c7
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
**To see all artworks, software, metadata, and creator for a specific post:**
|
| 25 |
+
```bash
|
| 26 |
+
python tool.py --post 00002b4d-120a-4e94-bae7-49b9c905bc05
|
| 27 |
+
# or using web URL:
|
| 28 |
+
python tool.py --post https://cara.app/post/00002b4d-120a-4e94-bae7-49b9c905bc05
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
**To find the post and creator that an artwork image belongs to:**
|
| 32 |
+
```bash
|
| 33 |
+
python tool.py --art tenaebron-S4TIL677BLm8bh_T0jB6I-post-cover-image.jpeg
|
| 34 |
+
# or using direct CDN link:
|
| 35 |
+
python tool.py --art https://cdn.cara.app/production/posts/93d6c843-1f4a-429d-8144-31e9099b95c6/tenaebron-S4TIL677BLm8bh_T0jB6I-post-cover-image.jpeg
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
### Database Structure (`catalog.db`)
|
| 41 |
+
|
| 42 |
+
The SQLite database contains 3 main tables (and 2 tracking tables):
|
| 43 |
+
|
| 44 |
+
#### `master_artworks_12m` (8,521,351 rows)
|
| 45 |
+
Contains all full-resolution master artwork uploads.
|
| 46 |
+
- `id`: Unique image ID (`<post_id>_slide_<number>`) `[PRIMARY KEY]`
|
| 47 |
+
- `post_id`: Post ID this artwork belongs to
|
| 48 |
+
- `author_slug`: Anonymized creator handle (`artist_<hex>`)
|
| 49 |
+
- `slide_number`: Order in the multi-image gallery (1, 2, 3...)
|
| 50 |
+
- `title`: Post title (with personal handles/links redacted as `[CENSORED]`)
|
| 51 |
+
- `cdn_url`: Direct high-res CDN link `(UNIQUE)`
|
| 52 |
+
- `width`: Image width in pixels
|
| 53 |
+
- `height`: Image height in pixels
|
| 54 |
+
- `created_at`: Upload timestamp
|
| 55 |
+
|
| 56 |
+
#### `artworks` (3,431,475 rows)
|
| 57 |
+
Contains all posts and cover thumbnails.
|
| 58 |
+
- `id`: Unique image ID (`<post_id>_<suffix>`) `[PRIMARY KEY]`
|
| 59 |
+
- `author_slug`: Anonymized creator handle (`artist_<hex>`)
|
| 60 |
+
- `author_id`: Anonymized creator UUID
|
| 61 |
+
- `post_id`: Post ID this artwork belongs to
|
| 62 |
+
- `cdn_url`: Cover image / thumbnail link `(UNIQUE)`
|
| 63 |
+
- `created_at`: Creation timestamp
|
| 64 |
+
- `downloaded`: Download status flag (`0` = pending, `1` = downloaded)
|
| 65 |
+
|
| 66 |
+
#### `post_metadata` (3,431,474 rows)
|
| 67 |
+
Contains all tags, software, descriptions, metrics, and audit statuses.
|
| 68 |
+
- `post_id`: Post ID `[PRIMARY KEY]`
|
| 69 |
+
- `author_slug`: Anonymized creator handle (`artist_<hex>`)
|
| 70 |
+
- `author_name`: Anonymized display name (`Artist <HEX>`)
|
| 71 |
+
- `title`: Post title (with personal handles/links redacted as `[CENSORED]`)
|
| 72 |
+
- `content`: Description / lore text (with social handles, emails, and links redacted as `[CENSORED]`)
|
| 73 |
+
- `softwares`: Software used (JSON array, e.g. `["Blender", "Photoshop"]`)
|
| 74 |
+
- `tags`: Categories and tags (JSON array, e.g. `["Illustration", "ConceptArt"]`)
|
| 75 |
+
- `raw_tags`: Typed tags (JSON array of objects, e.g. `[{"type": "category", "value": "Horror"}]`)
|
| 76 |
+
- `like_count`: Number of likes
|
| 77 |
+
- `comment_count`: Number of comments
|
| 78 |
+
- `status_code`: HTTP status (`200` = active, `404` = deleted post, `403` = private)
|
| 79 |
+
- `is_deleted`: `1` if post was removed, `0` if active
|
| 80 |
+
- `created_at`: Creation timestamp
|
| 81 |
+
|
| 82 |
+
#### Additional Tracking Tables:
|
| 83 |
+
- `indexed_artists` (3,267 rows): `author_id` (PK), `slug`, `artwork_count`
|
| 84 |
+
- `processed_posts` (3,431,475 rows): `post_id` (PK)
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
### Files in this Release
|
| 89 |
+
- `catalog.db`: SQLite database with all tables and B-Tree indexes (9.82 GB)
|
| 90 |
+
- `tool.py`: CLI dataset explorer script
|
| 91 |
+
- `README.md`: Dataset documentation
|
| 92 |
+
|
catalog.db
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b39c18e671eed0345656d96284a6469123ddaca2a46549df5f4ed6bd990ba267
|
| 3 |
+
size 10541236224
|
tool.py
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Cara Master Index Dataset Explorer CLI Tool
|
| 4 |
+
Zero External Dependencies (Runs on standard Python 3.7+ across Windows, macOS, Linux).
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import re
|
| 10 |
+
import json
|
| 11 |
+
import sqlite3
|
| 12 |
+
import argparse
|
| 13 |
+
from urllib.parse import urlparse
|
| 14 |
+
from collections import Counter
|
| 15 |
+
|
| 16 |
+
# Ensure UTF-8 output encoding for terminals
|
| 17 |
+
if hasattr(sys.stdout, "reconfigure"):
|
| 18 |
+
try:
|
| 19 |
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
| 20 |
+
except Exception:
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
# Dynamic discovery of catalog.db or catalog_anonymized.db (100% portable & anonymous)
|
| 24 |
+
DB_CANDIDATE_PATHS = [
|
| 25 |
+
"catalog_anonymized.db",
|
| 26 |
+
"catalog.db",
|
| 27 |
+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "catalog_anonymized.db"),
|
| 28 |
+
os.path.join(os.path.dirname(os.path.abspath(__file__)), "catalog.db"),
|
| 29 |
+
"../catalog_anonymized.db",
|
| 30 |
+
"../catalog.db",
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
COMMON_PLACEHOLDERS = [
|
| 34 |
+
"username",
|
| 35 |
+
"<username>",
|
| 36 |
+
"your_username",
|
| 37 |
+
"yourname",
|
| 38 |
+
"your_name",
|
| 39 |
+
"handle",
|
| 40 |
+
"<handle>",
|
| 41 |
+
"artist",
|
| 42 |
+
"<artist>"
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def find_database() -> str:
|
| 47 |
+
"""Auto-detects catalog database location dynamically."""
|
| 48 |
+
for path in DB_CANDIDATE_PATHS:
|
| 49 |
+
if os.path.exists(path) and os.path.getsize(path) > 1000000:
|
| 50 |
+
return path
|
| 51 |
+
return None
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def get_db_connection():
|
| 55 |
+
"""Connects to database with clean error guidance if missing."""
|
| 56 |
+
db_path = find_database()
|
| 57 |
+
if not db_path:
|
| 58 |
+
print("\n" + "=" * 80)
|
| 59 |
+
print("❌ DATABASE NOT FOUND: 'catalog_anonymized.db' or 'catalog.db'")
|
| 60 |
+
print("=" * 80)
|
| 61 |
+
print("Please make sure the database file is located in the same folder as this script!")
|
| 62 |
+
print(f"Current working directory: {os.getcwd()}")
|
| 63 |
+
print("=" * 80 + "\n")
|
| 64 |
+
sys.exit(1)
|
| 65 |
+
|
| 66 |
+
try:
|
| 67 |
+
conn = sqlite3.connect(db_path)
|
| 68 |
+
conn.row_factory = sqlite3.Row
|
| 69 |
+
return conn
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"\n❌ Error opening database: {e}\n")
|
| 72 |
+
sys.exit(1)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def sanitize_username(input_str: str) -> str:
|
| 76 |
+
"""Cleans artist handle input."""
|
| 77 |
+
if not input_str:
|
| 78 |
+
return ""
|
| 79 |
+
cleaned = input_str.strip().lstrip("<").rstrip(">").strip()
|
| 80 |
+
|
| 81 |
+
if "cara.app" in cleaned or "http" in cleaned:
|
| 82 |
+
path = urlparse(cleaned).path.strip("/")
|
| 83 |
+
parts = path.split("/")
|
| 84 |
+
if len(parts) > 0 and parts[0] not in ["post", "search", "explore"]:
|
| 85 |
+
cleaned = parts[0]
|
| 86 |
+
elif len(parts) > 1 and parts[0] == "user":
|
| 87 |
+
cleaned = parts[1]
|
| 88 |
+
|
| 89 |
+
return cleaned.lstrip("@").strip()
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def sanitize_post_id(input_str: str) -> str:
|
| 93 |
+
"""Cleans post input and extracts UUID."""
|
| 94 |
+
if not input_str:
|
| 95 |
+
return ""
|
| 96 |
+
cleaned = input_str.strip().lstrip("<").rstrip(">").strip()
|
| 97 |
+
|
| 98 |
+
uuid_match = re.search(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}', cleaned)
|
| 99 |
+
if uuid_match:
|
| 100 |
+
return uuid_match.group(0).lower()
|
| 101 |
+
|
| 102 |
+
if "/" in cleaned:
|
| 103 |
+
cleaned = cleaned.split("/")[-1].split("?")[0]
|
| 104 |
+
return cleaned.strip()
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def sanitize_art_query(input_str: str) -> str:
|
| 108 |
+
"""Extracts clean image hash / filename from CDN URL."""
|
| 109 |
+
if not input_str:
|
| 110 |
+
return ""
|
| 111 |
+
cleaned = input_str.strip().lstrip("<").rstrip(">").strip()
|
| 112 |
+
if "/" in cleaned:
|
| 113 |
+
cleaned = cleaned.split("/")[-1].split("?")[0]
|
| 114 |
+
return cleaned.strip()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def explore_user(username_raw: str, is_overview: bool = False):
|
| 118 |
+
"""
|
| 119 |
+
Explores all posts and artworks by an artist handle.
|
| 120 |
+
- is_overview=True: Shows stats and clean list of posts without image URLs.
|
| 121 |
+
- is_overview=False: Shows full breakdown with every master slide and thumbnail URL.
|
| 122 |
+
"""
|
| 123 |
+
username = sanitize_username(username_raw)
|
| 124 |
+
|
| 125 |
+
if username.lower() in [p.lower() for p in COMMON_PLACEHOLDERS]:
|
| 126 |
+
print("\n" + "=" * 80)
|
| 127 |
+
print(f"😅 I doubt your account is named '{username}' — did you forget to type your own name?")
|
| 128 |
+
print("Example: python tool.py --user mayonnaisejar1446 --overview")
|
| 129 |
+
print("=" * 80 + "\n")
|
| 130 |
+
return
|
| 131 |
+
|
| 132 |
+
if not username:
|
| 133 |
+
print("\n⚠️ Please specify an artist handle (e.g. 'python tool.py --user mayonnaisejar1446')\n")
|
| 134 |
+
return
|
| 135 |
+
|
| 136 |
+
conn = get_db_connection()
|
| 137 |
+
cur = conn.cursor()
|
| 138 |
+
|
| 139 |
+
# Resolve author by slug or author_id UUID
|
| 140 |
+
cur.execute("""
|
| 141 |
+
SELECT author_slug, author_id FROM artworks
|
| 142 |
+
WHERE author_slug = ? COLLATE NOCASE OR author_id = ?
|
| 143 |
+
LIMIT 1;
|
| 144 |
+
""", (username, username))
|
| 145 |
+
author_row = cur.fetchone()
|
| 146 |
+
if author_row:
|
| 147 |
+
username = author_row["author_slug"]
|
| 148 |
+
author_id = author_row["author_id"]
|
| 149 |
+
else:
|
| 150 |
+
cur.execute("SELECT DISTINCT author_slug FROM master_artworks_12m WHERE author_slug = ? COLLATE NOCASE;", (username,))
|
| 151 |
+
found_slug = cur.fetchone()
|
| 152 |
+
if not found_slug:
|
| 153 |
+
print("\n" + "=" * 80)
|
| 154 |
+
print(f"❌ Artist '{username}' was not found in the database.")
|
| 155 |
+
print("Tip: Double-check the handle or author UUID.")
|
| 156 |
+
print("=" * 80 + "\n")
|
| 157 |
+
conn.close()
|
| 158 |
+
return
|
| 159 |
+
username = found_slug["author_slug"]
|
| 160 |
+
author_id = None
|
| 161 |
+
|
| 162 |
+
# 1. Fetch Posts from artworks table
|
| 163 |
+
cur.execute("""
|
| 164 |
+
SELECT post_id, cdn_url as cover_url, created_at
|
| 165 |
+
FROM artworks
|
| 166 |
+
WHERE author_slug = ? COLLATE NOCASE
|
| 167 |
+
ORDER BY created_at DESC;
|
| 168 |
+
""", (username,))
|
| 169 |
+
posts = cur.fetchall()
|
| 170 |
+
|
| 171 |
+
# 2. Fetch Master Artworks
|
| 172 |
+
cur.execute("""
|
| 173 |
+
SELECT post_id, slide_number, title, cdn_url, width, height, created_at
|
| 174 |
+
FROM master_artworks_12m
|
| 175 |
+
WHERE author_slug = ? COLLATE NOCASE
|
| 176 |
+
ORDER BY post_id, slide_number;
|
| 177 |
+
""", (username,))
|
| 178 |
+
artworks = cur.fetchall()
|
| 179 |
+
|
| 180 |
+
# 3. Fetch Post Metadata
|
| 181 |
+
cur.execute("""
|
| 182 |
+
SELECT post_id, author_name, title, content, softwares, tags, like_count, comment_count, created_at
|
| 183 |
+
FROM post_metadata
|
| 184 |
+
WHERE author_slug = ? COLLATE NOCASE;
|
| 185 |
+
""", (username,))
|
| 186 |
+
meta_rows = {r["post_id"]: r for r in cur.fetchall()}
|
| 187 |
+
|
| 188 |
+
post_artworks = {}
|
| 189 |
+
for art in artworks:
|
| 190 |
+
post_artworks.setdefault(art["post_id"], []).append(art)
|
| 191 |
+
|
| 192 |
+
# Aggregate stats
|
| 193 |
+
display_name = None
|
| 194 |
+
all_softwares = []
|
| 195 |
+
all_tags = []
|
| 196 |
+
all_dates = []
|
| 197 |
+
|
| 198 |
+
for pid, meta in meta_rows.items():
|
| 199 |
+
if meta["author_name"] and not display_name:
|
| 200 |
+
display_name = meta["author_name"]
|
| 201 |
+
if meta["created_at"]:
|
| 202 |
+
all_dates.append(meta["created_at"][:10])
|
| 203 |
+
try:
|
| 204 |
+
sw = json.loads(meta["softwares"])
|
| 205 |
+
if isinstance(sw, list):
|
| 206 |
+
all_softwares.extend(sw)
|
| 207 |
+
except Exception:
|
| 208 |
+
pass
|
| 209 |
+
try:
|
| 210 |
+
tg = json.loads(meta["tags"])
|
| 211 |
+
if isinstance(tg, list):
|
| 212 |
+
all_tags.extend(tg)
|
| 213 |
+
except Exception:
|
| 214 |
+
pass
|
| 215 |
+
|
| 216 |
+
top_software = [s for s, _ in Counter(all_softwares).most_common(5)]
|
| 217 |
+
top_tags = [t for t, _ in Counter(all_tags).most_common(8)]
|
| 218 |
+
date_range = f"{min(all_dates)} to {max(all_dates)}" if all_dates else "N/A"
|
| 219 |
+
|
| 220 |
+
name_header = f"@{username}" + (f" ({display_name})" if display_name else "")
|
| 221 |
+
|
| 222 |
+
print("\n" + "=" * 80)
|
| 223 |
+
print(f"👤 ARTIST SUMMARY: {name_header}")
|
| 224 |
+
print("=" * 80)
|
| 225 |
+
if author_id:
|
| 226 |
+
print(f"🆔 Author UUID: {author_id}")
|
| 227 |
+
print(f"📊 Total Posts (Cover Thumbnails): {len(posts):,}")
|
| 228 |
+
print(f"🖼️ Total Master Artworks (Full-Res): {len(artworks):,}")
|
| 229 |
+
if top_software:
|
| 230 |
+
print(f"💻 Primary Software: {', '.join(top_software)}")
|
| 231 |
+
if top_tags:
|
| 232 |
+
print(f"🏷️ Top Tags: {', '.join(top_tags)}")
|
| 233 |
+
if all_dates:
|
| 234 |
+
print(f"📅 Activity Span: {date_range}")
|
| 235 |
+
print("=" * 80)
|
| 236 |
+
|
| 237 |
+
if is_overview:
|
| 238 |
+
print(f"📋 POSTS OVERVIEW ({len(posts)} posts): [Tip: Omit --overview to view all image links]")
|
| 239 |
+
print("-" * 80)
|
| 240 |
+
for idx, p in enumerate(posts, 1):
|
| 241 |
+
pid = p["post_id"]
|
| 242 |
+
arts = post_artworks.get(pid, [])
|
| 243 |
+
meta = meta_rows.get(pid)
|
| 244 |
+
|
| 245 |
+
title = "Untitled"
|
| 246 |
+
if meta and meta["title"] and meta["title"].strip():
|
| 247 |
+
title = meta["title"].strip()
|
| 248 |
+
elif arts and arts[0]["title"] and arts[0]["title"].strip():
|
| 249 |
+
title = arts[0]["title"].strip()
|
| 250 |
+
|
| 251 |
+
date_str = p["created_at"][:10] if p["created_at"] else "Unknown"
|
| 252 |
+
slides_info = f"{len(arts)} master slide(s)" if arts else "1 cover image"
|
| 253 |
+
|
| 254 |
+
print(f"[{idx}] 📌 {title} ({date_str}) | {slides_info}")
|
| 255 |
+
print(f" 🔗 https://cara.app/post/{pid}")
|
| 256 |
+
|
| 257 |
+
else:
|
| 258 |
+
print("📋 DETAILED POSTS & ARTWORK LINKS:")
|
| 259 |
+
print("-" * 80)
|
| 260 |
+
for idx, p in enumerate(posts, 1):
|
| 261 |
+
pid = p["post_id"]
|
| 262 |
+
arts = post_artworks.get(pid, [])
|
| 263 |
+
meta = meta_rows.get(pid)
|
| 264 |
+
|
| 265 |
+
title = "Untitled"
|
| 266 |
+
if meta and meta["title"] and meta["title"].strip():
|
| 267 |
+
title = meta["title"].strip()
|
| 268 |
+
elif arts and arts[0]["title"] and arts[0]["title"].strip():
|
| 269 |
+
title = arts[0]["title"].strip()
|
| 270 |
+
|
| 271 |
+
date_str = p["created_at"][:10] if p["created_at"] else "Unknown"
|
| 272 |
+
|
| 273 |
+
print(f"\n[{idx}] 📌 {title} ({date_str})")
|
| 274 |
+
print(f" 🔗 Post: https://cara.app/post/{pid}")
|
| 275 |
+
if p["cover_url"]:
|
| 276 |
+
print(f" 🖼️ Thumbnail: {p['cover_url']}")
|
| 277 |
+
|
| 278 |
+
if arts:
|
| 279 |
+
for a in arts:
|
| 280 |
+
res = f"[{a['width']}x{a['height']}]" if a['width'] and a['height'] else "[Full-Res]"
|
| 281 |
+
print(f" • Slide {a['slide_number']} {res}: {a['cdn_url']}")
|
| 282 |
+
|
| 283 |
+
print("\n" + "=" * 80 + "\n")
|
| 284 |
+
conn.close()
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def explore_post(post_raw: str):
|
| 288 |
+
"""Explores a post by URL or UUID."""
|
| 289 |
+
post_id = sanitize_post_id(post_raw)
|
| 290 |
+
if not post_id or post_id.lower() in ["post url", "<post url>", "post_id", "<post_id>"]:
|
| 291 |
+
print("\n" + "=" * 80)
|
| 292 |
+
print("😅 Did you copy '<Post url>' literally from the README?")
|
| 293 |
+
print("Example: python tool.py --post https://cara.app/post/5aac58cb-c33f-4622-9199-d6531e8f47f8")
|
| 294 |
+
print("=" * 80 + "\n")
|
| 295 |
+
return
|
| 296 |
+
|
| 297 |
+
conn = get_db_connection()
|
| 298 |
+
cur = conn.cursor()
|
| 299 |
+
|
| 300 |
+
cur.execute("""
|
| 301 |
+
SELECT id, post_id, author_slug, slide_number, title, cdn_url, width, height, created_at
|
| 302 |
+
FROM master_artworks_12m
|
| 303 |
+
WHERE post_id = ?
|
| 304 |
+
ORDER BY slide_number;
|
| 305 |
+
""", (post_id,))
|
| 306 |
+
slides = cur.fetchall()
|
| 307 |
+
|
| 308 |
+
cur.execute("SELECT cdn_url FROM artworks WHERE post_id = ?;", (post_id,))
|
| 309 |
+
cover_row = cur.fetchone()
|
| 310 |
+
cover_url = cover_row["cdn_url"] if cover_row else None
|
| 311 |
+
|
| 312 |
+
if not slides and not cover_url:
|
| 313 |
+
print("\n" + "=" * 80)
|
| 314 |
+
print(f"❌ Post ID '{post_id}' was not found in the master catalog.")
|
| 315 |
+
print("=" * 80 + "\n")
|
| 316 |
+
conn.close()
|
| 317 |
+
return
|
| 318 |
+
|
| 319 |
+
cur.execute("SELECT * FROM post_metadata WHERE post_id = ?;", (post_id,))
|
| 320 |
+
meta = cur.fetchone()
|
| 321 |
+
|
| 322 |
+
author = slides[0]["author_slug"] if slides else (meta["author_slug"] if meta else "unknown")
|
| 323 |
+
title = (slides[0]["title"] if slides and slides[0]["title"] else None) or (meta["title"] if meta and meta["title"] else "Untitled")
|
| 324 |
+
|
| 325 |
+
print("\n" + "=" * 80)
|
| 326 |
+
print(f"📌 POST ID: {post_id}")
|
| 327 |
+
print(f"👤 ARTIST: @{author}")
|
| 328 |
+
print(f"🎨 TITLE: {title}")
|
| 329 |
+
print(f"🔗 WEB LINK: https://cara.app/post/{post_id}")
|
| 330 |
+
|
| 331 |
+
if cover_url:
|
| 332 |
+
print(f"🖼️ THUMBNAIL: {cover_url}")
|
| 333 |
+
|
| 334 |
+
if meta:
|
| 335 |
+
try:
|
| 336 |
+
tags = json.loads(meta["tags"])
|
| 337 |
+
softwares = json.loads(meta["softwares"])
|
| 338 |
+
if softwares:
|
| 339 |
+
print(f"💻 SOFTWARE: {softwares}")
|
| 340 |
+
if tags:
|
| 341 |
+
print(f"🏷️ TAGS: {tags}")
|
| 342 |
+
if meta["like_count"] is not None or meta["comment_count"] is not None:
|
| 343 |
+
likes = meta["like_count"] if meta["like_count"] is not None else 0
|
| 344 |
+
comments = meta["comment_count"] if meta["comment_count"] is not None else 0
|
| 345 |
+
print(f"❤️ ENGAGEMENT: {likes:,} likes | {comments:,} comments")
|
| 346 |
+
if meta["content"]:
|
| 347 |
+
print(f"\n📝 POST BODY:\n{meta['content'].strip()}")
|
| 348 |
+
except Exception:
|
| 349 |
+
pass
|
| 350 |
+
|
| 351 |
+
if slides:
|
| 352 |
+
print("\n🖼️ MASTER ARTWORKS (" + str(len(slides)) + " slide(s)):")
|
| 353 |
+
print("-" * 80)
|
| 354 |
+
for s in slides:
|
| 355 |
+
res = f"{s['width']}x{s['height']}" if s['width'] and s['height'] else "Full-Res"
|
| 356 |
+
print(f" • Slide {s['slide_number']} [{res}]: {s['cdn_url']}")
|
| 357 |
+
print("=" * 80 + "\n")
|
| 358 |
+
conn.close()
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def explore_artwork(art_raw: str):
|
| 362 |
+
"""Reverse traces an artwork CDN link or image filename back to its post and creator."""
|
| 363 |
+
raw_clean = art_raw.strip().lstrip("<").rstrip(">").strip()
|
| 364 |
+
art_hash = sanitize_art_query(raw_clean)
|
| 365 |
+
|
| 366 |
+
if not art_hash or art_hash.lower() in ["cdn url", "<cdn url>", "cdn_url", "<cdn_url>"]:
|
| 367 |
+
print("\n" + "=" * 80)
|
| 368 |
+
print("😅 Did you copy '<CDN url>' literally from the README?")
|
| 369 |
+
print("Example: python tool.py --art otawrou-8L8tjCPtnNl1TStnB3Psu-0000-00091.gif")
|
| 370 |
+
print("=" * 80 + "\n")
|
| 371 |
+
return
|
| 372 |
+
|
| 373 |
+
conn = get_db_connection()
|
| 374 |
+
cur = conn.cursor()
|
| 375 |
+
|
| 376 |
+
# Fast Path 1: Exact URL match
|
| 377 |
+
cur.execute("SELECT post_id, author_slug, slide_number, title, cdn_url, width, height, created_at FROM master_artworks_12m WHERE cdn_url = ?;", (raw_clean,))
|
| 378 |
+
match = cur.fetchone()
|
| 379 |
+
|
| 380 |
+
# Fast Path 2: Exact Filename match
|
| 381 |
+
if not match:
|
| 382 |
+
cur.execute("SELECT post_id, author_slug, slide_number, title, cdn_url, width, height, created_at FROM master_artworks_12m WHERE cdn_url LIKE ?;", (f"https://cdn.cara.app/production/posts/%/{art_hash}",))
|
| 383 |
+
match = cur.fetchone()
|
| 384 |
+
|
| 385 |
+
# Fallback Path 3: Substring search
|
| 386 |
+
if not match:
|
| 387 |
+
cur.execute("SELECT post_id, author_slug, slide_number, title, cdn_url, width, height, created_at FROM master_artworks_12m WHERE cdn_url LIKE ?;", (f"%{art_hash}%",))
|
| 388 |
+
match = cur.fetchone()
|
| 389 |
+
|
| 390 |
+
# Fallback Path 4: Check cover thumbnails in artworks
|
| 391 |
+
if not match:
|
| 392 |
+
cur.execute("SELECT post_id, author_slug, cdn_url, created_at FROM artworks WHERE cdn_url LIKE ?;", (f"%{art_hash}%",))
|
| 393 |
+
cover_match = cur.fetchone()
|
| 394 |
+
if cover_match:
|
| 395 |
+
print("\n" + "=" * 80)
|
| 396 |
+
print("🔍 REVERSE ARTWORK TRACER (Feed Cover Thumbnail)")
|
| 397 |
+
print("=" * 80)
|
| 398 |
+
print(f"🖼️ Thumbnail: {cover_match['cdn_url']}")
|
| 399 |
+
print(f"📌 Post ID: {cover_match['post_id']}")
|
| 400 |
+
print(f"👤 Creator: @{cover_match['author_slug']}")
|
| 401 |
+
print(f"🔗 Direct Web: https://cara.app/post/{cover_match['post_id']}")
|
| 402 |
+
print("=" * 80 + "\n")
|
| 403 |
+
conn.close()
|
| 404 |
+
return
|
| 405 |
+
|
| 406 |
+
if not match:
|
| 407 |
+
print("\n" + "=" * 80)
|
| 408 |
+
print(f"❌ Artwork image '{art_hash}' was not found in the database.")
|
| 409 |
+
print("=" * 80 + "\n")
|
| 410 |
+
conn.close()
|
| 411 |
+
return
|
| 412 |
+
|
| 413 |
+
pid = match["post_id"]
|
| 414 |
+
cur.execute("SELECT * FROM post_metadata WHERE post_id = ?;", (pid,))
|
| 415 |
+
meta = cur.fetchone()
|
| 416 |
+
|
| 417 |
+
print("\n" + "=" * 80)
|
| 418 |
+
print("🔍 REVERSE ARTWORK TRACER (Master Full-Res Artwork)")
|
| 419 |
+
print("=" * 80)
|
| 420 |
+
print(f"🖼️ Image Link: {match['cdn_url']}")
|
| 421 |
+
print(f"📐 Resolution: {match['width']}x{match['height']} (Slide {match['slide_number']})")
|
| 422 |
+
print(f"📌 Post ID: {match['post_id']}")
|
| 423 |
+
print(f"👤 Creator: @{match['author_slug']}")
|
| 424 |
+
print(f"🎨 Title: {match['title'] or 'Untitled'}")
|
| 425 |
+
print(f"📅 Upload Date: {match['created_at']}")
|
| 426 |
+
print(f"🔗 Direct Web: https://cara.app/post/{match['post_id']}")
|
| 427 |
+
|
| 428 |
+
if meta:
|
| 429 |
+
try:
|
| 430 |
+
tags = json.loads(meta["tags"])
|
| 431 |
+
if tags:
|
| 432 |
+
print(f"🏷️ Post Tags: {tags[:6]}")
|
| 433 |
+
except Exception:
|
| 434 |
+
pass
|
| 435 |
+
|
| 436 |
+
print("=" * 80 + "\n")
|
| 437 |
+
conn.close()
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def interactive_menu():
|
| 441 |
+
"""Interactive CLI menu when run with zero arguments."""
|
| 442 |
+
print("\n" + "=" * 80)
|
| 443 |
+
print("🎨 CARA MASTER INDEX DATASET EXPLORER")
|
| 444 |
+
print("=" * 80)
|
| 445 |
+
print("Choose an option:")
|
| 446 |
+
print(" 1. Look up an Artist / Username (Summary Overview)")
|
| 447 |
+
print(" 2. Look up an Artist / Username (Full Artwork Links)")
|
| 448 |
+
print(" 3. Look up a Post Link / Post UUID")
|
| 449 |
+
print(" 4. Reverse Trace an Artwork CDN Image URL")
|
| 450 |
+
print(" 5. Exit")
|
| 451 |
+
print("=" * 80)
|
| 452 |
+
|
| 453 |
+
choice = input("\nEnter choice (1-5): ").strip()
|
| 454 |
+
if choice == "1":
|
| 455 |
+
user_input = input("Enter username or profile URL: ").strip()
|
| 456 |
+
explore_user(user_input, is_overview=True)
|
| 457 |
+
elif choice == "2":
|
| 458 |
+
user_input = input("Enter username or profile URL: ").strip()
|
| 459 |
+
explore_user(user_input, is_overview=False)
|
| 460 |
+
elif choice == "3":
|
| 461 |
+
post_input = input("Enter post URL or UUID: ").strip()
|
| 462 |
+
explore_post(post_input)
|
| 463 |
+
elif choice == "4":
|
| 464 |
+
art_input = input("Enter CDN URL or image filename: ").strip()
|
| 465 |
+
explore_artwork(art_input)
|
| 466 |
+
elif choice == "5" or choice.lower() in ["q", "exit", "quit"]:
|
| 467 |
+
print("Goodbye!")
|
| 468 |
+
sys.exit(0)
|
| 469 |
+
else:
|
| 470 |
+
print("Invalid choice. Exiting.")
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
def main():
|
| 474 |
+
parser = argparse.ArgumentParser(description="Cara Master Index Dataset CLI Tool")
|
| 475 |
+
parser.add_argument("--user", help="Query creator handle (e.g. --user alex123)")
|
| 476 |
+
parser.add_argument("--overview", action="store_true", help="Clean summary overview (disables showing image links)")
|
| 477 |
+
parser.add_argument("--post", help="Query post metadata, lore & gallery (e.g. --post https://cara.app/post/...)")
|
| 478 |
+
parser.add_argument("--art", help="Reverse trace an image CDN link back to creator & post")
|
| 479 |
+
|
| 480 |
+
if len(sys.argv) == 1:
|
| 481 |
+
interactive_menu()
|
| 482 |
+
return
|
| 483 |
+
|
| 484 |
+
args = parser.parse_args()
|
| 485 |
+
|
| 486 |
+
if args.user:
|
| 487 |
+
explore_user(args.user, is_overview=args.overview)
|
| 488 |
+
elif args.post:
|
| 489 |
+
explore_post(args.post)
|
| 490 |
+
elif args.art:
|
| 491 |
+
explore_artwork(args.art)
|
| 492 |
+
else:
|
| 493 |
+
interactive_menu()
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
if __name__ == "__main__":
|
| 497 |
+
main()
|