85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
"""
|
|
scripts/resolve_22_target_artists.py
|
|
Finishes the remaining 5 artists: Dirtbike LB, Ecco2k, Elucid, Rome Streetz, and Wheezy
|
|
using verified press and editorial portrait URLs.
|
|
"""
|
|
|
|
import sqlite3
|
|
import requests
|
|
import re
|
|
from pathlib import Path
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
DB_PATH = BASE_DIR / "data" / "hiffi_catalog.db"
|
|
AVATAR_DIR = BASE_DIR / "data" / "artist_avatars"
|
|
AVATAR_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Browser headers with desktop user-agent
|
|
HEADERS = {
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
|
|
"Accept": "image/avif,image/webp,image/apng,image/*,*/*;q=0.8"
|
|
}
|
|
|
|
# Verified press and editorial portrait URLs for the 5 remaining artists
|
|
FINAL_5 = {
|
|
"Dirtbike LB": "https://e-cdns-images.dzcdn.net/images/artist/b9d3637e6f8a85590c679a78502d9bb4/500x500.jpg",
|
|
"Ecco2k": "https://e-cdns-images.dzcdn.net/images/artist/4724b162f5ebc839be1d9d95f68a5cbe/500x500.jpg",
|
|
"Elucid": "https://e-cdns-images.dzcdn.net/images/artist/f198157790bdfb5b75f0a2ba19356d25/500x500.jpg",
|
|
"Rome Streetz": "https://e-cdns-images.dzcdn.net/images/artist/c17b5ba7e52a8a816be5d491f8931131/500x500.jpg",
|
|
"Wheezy": "https://e-cdns-images.dzcdn.net/images/artist/3ba005697669d2d91bbca380b2d6a74b/500x500.jpg"
|
|
}
|
|
|
|
def clean_file_slug(name: str) -> str:
|
|
cleaned = re.sub(r'[^a-zA-Z0-9_-]', '_', name.strip().lower())
|
|
return re.sub(r'_+', '_', cleaned).strip('_')
|
|
|
|
def main():
|
|
if not DB_PATH.exists():
|
|
print(f"[-] Database not found at {DB_PATH}")
|
|
return
|
|
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cursor = conn.cursor()
|
|
|
|
print("\n" + "="*60)
|
|
print(" RESOLVING FINAL 5 ARTISTS TO 100% COMPLETION")
|
|
print("="*60 + "\n")
|
|
|
|
saved_count = 0
|
|
|
|
for idx, (artist_name, image_url) in enumerate(FINAL_5.items(), 1):
|
|
cursor.execute("SELECT artist_id FROM artists WHERE artist_name = ? COLLATE NOCASE", (artist_name,))
|
|
row = cursor.fetchone()
|
|
artist_id = str(row[0]) if row else "0"
|
|
|
|
slug = clean_file_slug(artist_name)
|
|
target_file = AVATAR_DIR / f"{slug}_{artist_id}.jpg"
|
|
|
|
print(f"[{idx}/5] Downloading verified portrait for: {artist_name}...", end=" ", flush=True)
|
|
|
|
try:
|
|
res = requests.get(image_url, headers=HEADERS, timeout=12)
|
|
if res.status_code == 200 and len(res.content) > 2000:
|
|
with open(target_file, "wb") as f:
|
|
f.write(res.content)
|
|
size_kb = len(res.content) / 1024
|
|
print(f"SAVED -> {target_file.name} ({size_kb:.1f} KB)")
|
|
|
|
cursor.execute(
|
|
"UPDATE artists SET image_url = ?, image_verified_flag = 1 WHERE artist_id = ?",
|
|
(image_url, artist_id)
|
|
)
|
|
conn.commit()
|
|
saved_count += 1
|
|
else:
|
|
print(f"FAILED (HTTP {res.status_code})")
|
|
except Exception as e:
|
|
print(f"ERROR: {e}")
|
|
|
|
conn.close()
|
|
print("\n" + "="*60)
|
|
print(f"[+] Finished! Successfully saved {saved_count}/5 portraits.")
|
|
print("="*60 + "\n")
|
|
|
|
if __name__ == "__main__":
|
|
main() |