Files
hiffi-artist-intelligence/scripts/fix_exact_portraits.py
T
Srilekha 78a46a8dbe
HIFFI Multi-Platform CI / test (3.12) (push) Successful in 50s
HIFFI Multi-Platform CI / test (3.11) (push) Successful in 50s
feat: finalize root api.py with X-Auth-Secret auth security and clean pure sales cohort
2026-11-04 16:49:39 +05:30

86 lines
3.1 KiB
Python

"""
scripts/fix_exact_portraits.py
Directly fetches unblocked CDN portraits for:
- $uicideboy$
- 100k Track
- AZ
- Aminé
And audits any remaining fallback stubs across the entire 500 cohort.
"""
from pathlib import Path
import sys
import requests
ROOT_DIR = Path(__file__).resolve().parent.parent
if str(ROOT_DIR) not in sys.path:
sys.path.insert(0, str(ROOT_DIR))
from core.database import get_connection
def fetch_deezer_portrait(query_term: str):
"""Fetches high-res unblocked Deezer artist avatar."""
url = f"https://api.deezer.com/search/artist?q={query_term}&limit=5"
try:
r = requests.get(url, timeout=10)
if r.status_code == 200:
artists = r.json().get("data", [])
for a in artists:
img = a.get("picture_xl") or a.get("picture_big") or a.get("picture_medium")
if img and "artist-default" not in img:
return img
except Exception:
pass
return None
def main():
print("=" * 65)
print("HIFFI INTELLIGENCE: EXACT ARTIST PORTRAIT DIRECT RESOLUTION")
print("=" * 65)
conn = get_connection()
cur = conn.cursor()
# Exact direct CDN portraits for the 4 specific artists
direct_targets = {
"$uicideboy$": fetch_deezer_portrait("Suicideboys") or "https://e-cdns-images.dzcdn.net/images/artist/f3a0932bb82f5342a8b3017a4c7ebbb4/1000x1000-000000-80-0-0.jpg",
"100k Track": fetch_deezer_portrait("100k Track") or "https://e-cdns-images.dzcdn.net/images/artist/b13a17e0e7a17730e206b009e43685e1/1000x1000-000000-80-0-0.jpg",
"AZ": fetch_deezer_portrait("AZ") or "https://e-cdns-images.dzcdn.net/images/artist/81f80875c7438c8beab8ec7c524029ce/1000x1000-000000-80-0-0.jpg",
"Aminé": fetch_deezer_portrait("Amine") or "https://e-cdns-images.dzcdn.net/images/artist/99e2850901e19d2da079f8e4a9e53ce9/1000x1000-000000-80-0-0.jpg",
}
for name, img_url in direct_targets.items():
if img_url:
cur.execute("""
UPDATE artists
SET image_url = ?,
image_verified_flag = 1
WHERE LOWER(artist_name) = LOWER(?)
""", (img_url, name))
print(f"[UPDATED] {name:<15} -> {img_url}")
conn.commit()
# Scan for any other artist whose current image contains 'ui-avatars' or Last.fm star
cur.execute("""
SELECT artist_id, artist_name, image_url
FROM artists
WHERE image_url LIKE '%ui-avatars.com%'
OR image_url LIKE '%2a96cbd8b46e442fc41c2b86b821562f%'
""")
stubs = cur.fetchall()
print(f"\nRemaining stub avatars in catalog: {len(stubs)}")
for artist_id, artist_name, _ in stubs:
fallback_img = fetch_deezer_portrait(artist_name)
if fallback_img:
cur.execute("UPDATE artists SET image_url = ?, image_verified_flag = 1 WHERE artist_id = ?", (fallback_img, artist_id))
print(f"[RESOLVED] {artist_name} -> {fallback_img}")
conn.commit()
conn.close()
print("\n" + "=" * 65)
print("Exact portraits committed to database.")
print("=" * 65)
if __name__ == "__main__":
main()