mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
actors the i dont know xD
This commit is contained in:
@@ -656,13 +656,32 @@ class StashSyncService extends BaseSyncService
|
||||
$name = $performer['name'] ?? '';
|
||||
if (empty($name)) return null;
|
||||
|
||||
// Check if actor already exists
|
||||
// Check if actor already exists by name or alias
|
||||
// First check by exact name
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT id, name, thumbnail_path, metadata 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 not found by name, check aliases in PHP
|
||||
if (!$existingActor) {
|
||||
$stmt = $this->pdo->prepare("SELECT id, name, thumbnail_path, metadata FROM actors");
|
||||
$stmt->execute();
|
||||
$allActors = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($allActors as $actor) {
|
||||
$metadata = json_decode($actor['metadata'] ?? '{}', true);
|
||||
$aliases = $metadata['aliases'] ?? [];
|
||||
if (is_array($aliases) && in_array($name, $aliases)) {
|
||||
$existingActor = $actor;
|
||||
$this->logProgress("Found existing actor '{$actor['name']}' by alias '{$name}'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare rich metadata from Stash performer data
|
||||
$actorMetadata = [
|
||||
'stash_id' => $performer['id'] ?? null,
|
||||
@@ -908,8 +927,9 @@ class StashSyncService extends BaseSyncService
|
||||
try {
|
||||
$this->logProgress('Starting existing performers sync with Stash...');
|
||||
|
||||
echo "Starting existing performers sync with Stash..\n";
|
||||
// Get all existing actors from database
|
||||
$stmt = $this->pdo->prepare("SELECT id, name, metadata FROM actors ORDER BY name ASC");
|
||||
$stmt = $this->pdo->prepare("SELECT id, name, metadata FROM actors WHERE id IN (SELECT actor_id FROM actor_adult_video) ORDER BY name ASC");
|
||||
$stmt->execute();
|
||||
$existingActors = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
@@ -392,18 +392,65 @@ class XbvrSyncService extends BaseSyncService
|
||||
|
||||
if (empty($actorName)) continue;
|
||||
|
||||
// Try to get detailed actor information from XBVR
|
||||
$detailedActorData = $this->getActorDetails($actorName, $actorData);
|
||||
// Handle XBVR "aka:" format (e.g., "aka:Bella Luna,Bella Luna")
|
||||
$actorNames = $this->parseXbvrActorNames($actorName);
|
||||
|
||||
$actor = $this->getOrCreateActor($detailedActorData);
|
||||
if ($actor) {
|
||||
$actors[] = $actor;
|
||||
$foundActor = null;
|
||||
foreach ($actorNames as $name) {
|
||||
$detailedActorData = $this->getActorDetails($name, $actorData);
|
||||
$detailedActorData['name'] = $name; // Ensure the name is set correctly
|
||||
|
||||
$actor = $this->getOrCreateActor($detailedActorData);
|
||||
if ($actor) {
|
||||
$foundActor = $actor;
|
||||
break; // Use the first found actor
|
||||
}
|
||||
}
|
||||
|
||||
// If no actor found with any of the names, create one with the first name
|
||||
if (!$foundActor && !empty($actorNames)) {
|
||||
$firstName = $actorNames[0];
|
||||
$detailedActorData = $this->getActorDetails($firstName, $actorData);
|
||||
$detailedActorData['name'] = $firstName;
|
||||
|
||||
$foundActor = $this->getOrCreateActor($detailedActorData);
|
||||
}
|
||||
|
||||
if ($foundActor) {
|
||||
$actors[] = $foundActor;
|
||||
}
|
||||
}
|
||||
|
||||
return $actors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse XBVR actor names that may contain "aka:" format
|
||||
* Example: "aka:Bella Luna,Bella Luna" -> ["Bella Luna", "Bella Luna"]
|
||||
*/
|
||||
private function parseXbvrActorNames(string $actorName): array
|
||||
{
|
||||
// Check if the name starts with "aka:"
|
||||
if (strpos($actorName, 'aka:') === 0) {
|
||||
// Remove "aka:" prefix and split by comma
|
||||
$namesPart = substr($actorName, 4); // Remove "aka:"
|
||||
$names = array_map('trim', explode(',', $namesPart));
|
||||
|
||||
// Filter out empty names
|
||||
$names = array_filter($names, function($name) {
|
||||
return !empty(trim($name));
|
||||
});
|
||||
|
||||
if (!empty($names)) {
|
||||
$this->logProgress("Parsed XBVR aka format '{$actorName}' into names: " . implode(', ', $names));
|
||||
return $names;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the original name if not in aka format
|
||||
return [$actorName];
|
||||
}
|
||||
|
||||
private function getActorDetails(string $actorName, $actorData): array
|
||||
{
|
||||
// If we already have detailed actor data from the scene, use it
|
||||
@@ -587,13 +634,20 @@ class XbvrSyncService extends BaseSyncService
|
||||
$name = $actorData['name'] ?? '';
|
||||
if (empty($name)) return null;
|
||||
|
||||
// Check if actor already exists
|
||||
// Check if actor already exists by name or alias
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT id, name, thumbnail_path, metadata FROM actors WHERE name = :name
|
||||
SELECT id, name, thumbnail_path, metadata FROM actors
|
||||
WHERE name = :name
|
||||
OR JSON_CONTAINS(metadata->'$.aliases', :name)
|
||||
");
|
||||
$stmt->execute(['name' => $name]);
|
||||
$existingActor = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
// If found by alias, log it for debugging
|
||||
if ($existingActor && $existingActor['name'] !== $name) {
|
||||
$this->logProgress("Found existing actor '{$existingActor['name']}' by alias '{$name}'");
|
||||
}
|
||||
|
||||
// Prepare metadata from XBVR actor data
|
||||
$actorMetadata = [
|
||||
'xbvr_id' => $actorData['xbvr_id'] ?? $actorData['id'] ?? null,
|
||||
|
||||
Reference in New Issue
Block a user