dont know ?

This commit is contained in:
Lars Behrends
2025-11-03 23:34:36 +01:00
parent 7a7977d8b0
commit 1ec6016b10
27 changed files with 6854 additions and 3361 deletions

View File

@@ -465,15 +465,9 @@ class StashSyncService extends BaseSyncService
$sceneData['local_cover_path'] = $existingMetadata['local_cover_path'] ?? null;
$sceneData['local_screenshot_path'] = $existingMetadata['local_screenshot_path'] ?? null;
}
// Handle performers/actors
// Handle performers/actors with full metadata
$performers = $sceneData['performers'] ?? [];
$actorNames = [];
$performerImages = [];
foreach ($performers as $performer) {
$actorNames[] = $performer['name'];
$performerImages[$performer['name']] = $performer['image_path'] ?? null;
}
$actors = $this->syncActors($actorNames, $performerImages);
$actors = $this->syncActors($performers);
$sceneData = [
'title' => $sceneData['title'] ?: 'Untitled Scene',
@@ -618,15 +612,14 @@ class StashSyncService extends BaseSyncService
}
}
private function syncActors(array $actorNames, array $performerImages = []): array
private function syncActors(array $performers): array
{
$actors = [];
foreach ($actorNames as $actorName) {
if (empty($actorName)) continue;
foreach ($performers as $performer) {
if (empty($performer['name'])) continue;
$imagePath = $performerImages[$actorName] ?? null;
$actor = $this->getOrCreateActor($actorName, $imagePath);
$actor = $this->getOrCreateActor($performer);
if ($actor) {
$actors[] = $actor;
}
@@ -635,25 +628,63 @@ class StashSyncService extends BaseSyncService
return $actors;
}
private function getOrCreateActor(string $name, ?string $imagePath = null): ?array
private function getOrCreateActor(array $performer): ?array
{
$name = $performer['name'] ?? '';
if (empty($name)) return null;
// Check if actor already exists
$stmt = $this->pdo->prepare("
SELECT id, name, thumbnail_path FROM actors WHERE name = :name
SELECT id, name, thumbnail_path, metadata FROM actors WHERE name = :name
");
$stmt->execute(['name' => $name]);
$existingActor = $stmt->fetch(PDO::FETCH_ASSOC);
if ($existingActor) {
return [
'id' => $existingActor['id'],
'name' => $existingActor['name'],
'thumbnail_path' => $existingActor['thumbnail_path']
];
}
// Prepare rich metadata from Stash performer data
$actorMetadata = [
'stash_id' => $performer['id'] ?? null,
'stash_url' => $performer['url'] ?? null,
'disambiguation' => $performer['disambiguation'] ?? '',
'gender' => $performer['gender'] ?? null,
'birth_date' => $performer['birthdate'] ?? null,
'death_date' => $performer['death_date'] ?? null,
'ethnicity' => $performer['ethnicity'] ?? null,
'country' => $performer['country'] ?? null,
'nationality' => $performer['country'] ?? null, // Map country to nationality
'eye_color' => $performer['eye_color'] ?? null,
'hair_color' => $performer['hair_color'] ?? null,
'height' => $performer['height_cm'] ? $performer['height_cm'] . 'cm' : null,
'measurements' => $performer['measurements'] ?? null,
'cup_size' => $this->extractCupSize($performer['measurements'] ?? ''),
'weight' => $performer['weight'] ? $performer['weight'] . 'kg' : null,
'piercings' => $performer['piercings'] ?? null,
'tattoos' => $performer['tattoos'] ?? null,
'fake_tits' => $performer['fake_tits'] ?? null,
'penis_length' => $performer['penis_length'] ?? null,
'circumcised' => $performer['circumcised'] ?? null,
'career_length' => $performer['career_length'] ?? null,
'aliases' => $performer['alias_list'] ?? [],
'favorite' => $performer['favorite'] ?? false,
'ignore_auto_tag' => $performer['ignore_auto_tag'] ?? false,
'scene_count' => $performer['scene_count'] ?? 0,
'details' => $performer['details'] ?? null,
'stash_created_at' => $performer['created_at'] ?? null,
'stash_updated_at' => $performer['updated_at'] ?? null,
'social_media' => [
'website' => $performer['url'] ?? null
],
'adult_specific' => [
'debut_year' => $this->extractDebutYear($performer['career_length'] ?? ''),
'retirement_year' => $this->extractRetirementYear($performer['career_length'] ?? ''),
'active' => $this->isActivePerformer($performer['career_length'] ?? ''),
'genres' => [],
'specialties' => []
]
];
// Try to download performer image if available
$thumbnailPath = null;
$imagePath = $performer['image_path'] ?? null;
if ($imagePath) {
// Validate image path before constructing URL
if (!empty(trim($imagePath))) {
@@ -667,7 +698,7 @@ class StashSyncService extends BaseSyncService
$imageUrl = "{$this->baseUrl}" . $imagePath;
} else {
// Relative path - assume it's in performer images directory
$imageUrl = "{$this->baseUrl}/performer/" . $imagePath;
$imageUrl = "{$this->baseUrl}/performer/" . $performer['id'] . "/" . $imagePath;
}
// Validate the constructed URL
@@ -690,17 +721,56 @@ class StashSyncService extends BaseSyncService
}
}
if ($existingActor) {
// Update existing actor with new metadata if it's more complete
$existingMetadata = json_decode($existingActor['metadata'] ?? '{}', true);
// Check if we should update - prefer more complete data
$shouldUpdate = false;
if (empty($existingMetadata['stash_id']) && !empty($actorMetadata['stash_id'])) {
$shouldUpdate = true;
} elseif (!empty($thumbnailPath) && empty($existingActor['thumbnail_path'])) {
$shouldUpdate = true;
}
if ($shouldUpdate) {
$stmt = $this->pdo->prepare("
UPDATE actors
SET thumbnail_path = COALESCE(:thumbnail_path, thumbnail_path),
metadata = :metadata,
updated_at = NOW()
WHERE id = :id
");
$stmt->execute([
'id' => $existingActor['id'],
'thumbnail_path' => $thumbnailPath ?: $existingActor['thumbnail_path'],
'metadata' => json_encode(array_merge($existingMetadata, $actorMetadata))
]);
$this->logProgress("Updated existing actor {$name} with Stash metadata");
}
return [
'id' => $existingActor['id'],
'name' => $existingActor['name'],
'thumbnail_path' => $thumbnailPath ?: $existingActor['thumbnail_path']
];
}
// Create new actor with full metadata
try {
$stmt = $this->pdo->prepare("
INSERT INTO actors (name, thumbnail_path, created_at, updated_at)
VALUES (:name, :thumbnail_path, NOW(), NOW())
INSERT INTO actors (name, thumbnail_path, metadata, created_at, updated_at)
VALUES (:name, :thumbnail_path, :metadata, NOW(), NOW())
");
$stmt->execute([
'name' => $name,
'thumbnail_path' => $thumbnailPath
'thumbnail_path' => $thumbnailPath,
'metadata' => json_encode($actorMetadata)
]);
$actorId = $this->pdo->lastInsertId();
$this->logProgress("Created new actor {$name} with full Stash metadata");
return [
'id' => $actorId,
'name' => $name,
@@ -712,6 +782,55 @@ class StashSyncService extends BaseSyncService
}
}
private function extractCupSize(string $measurements): ?string
{
if (empty($measurements)) return null;
// Try to extract cup size from measurements like "34C-24-35"
$parts = explode('-', $measurements);
if (count($parts) >= 1) {
$firstPart = trim($parts[0]);
// Look for cup size pattern (number followed by letter)
if (preg_match('/(\d+)([A-Z])/', $firstPart, $matches)) {
return $matches[2];
}
}
return null;
}
private function extractDebutYear(string $careerLength): ?string
{
if (empty($careerLength)) return null;
// Extract debut year from patterns like "2015 -" or "2015 - 2020"
if (preg_match('/(\d{4})\s*-\s*(\d{4})?/', $careerLength, $matches)) {
return $matches[1];
}
return null;
}
private function extractRetirementYear(string $careerLength): ?string
{
if (empty($careerLength)) return null;
// Extract retirement year from patterns like "2015 - 2020"
if (preg_match('/\d{4}\s*-\s*(\d{4})/', $careerLength, $matches)) {
return $matches[1];
}
return null;
}
private function isActivePerformer(string $careerLength): bool
{
if (empty($careerLength)) return false;
// Check if career is still active (ends with " -")
return str_ends_with(trim($careerLength), '-');
}
protected function getProcessedCount(): int
{
return $this->processedCount;