actors / poster images

This commit is contained in:
Lars Behrends
2025-10-17 13:45:57 +02:00
parent 929ee43001
commit f4c1cfc164
6 changed files with 195 additions and 54 deletions

View File

@@ -21,16 +21,21 @@ class StashSyncService extends BaseSyncService
public function __construct(PDO $pdo, array $source)
{
parent::__construct($pdo, $source);
// Initialize properties first before using them
$this->apiKey = $source['api_key'];
$this->baseUrl = rtrim($source['api_url'], '/');
$this->httpClient = new Client([
'timeout' => 60, // Stash can be slow
'headers' => [
'User-Agent' => 'MediaCollector/1.0',
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
'ApiKey' => $this->apiKey // Now safe to access
]
]);
$this->apiKey = $source['api_key'];
$this->baseUrl = rtrim($source['api_url'], '/');
$this->imageDownloader = new ImageDownloader();
$this->imageDownloader = new ImageDownloader('public/images', $this->apiKey);
}
protected function executeSync(string $syncType): void
@@ -282,12 +287,24 @@ class StashSyncService extends BaseSyncService
// Stash provides paths.screenshot for screenshot
if (!empty($sceneData['paths']['screenshot'])) {
// Convert relative path to full URL
$screenshotUrl = "{$this->baseUrl}/" . ltrim($sceneData['paths']['screenshot'], '/');
$screenshotPath = $sceneData['paths']['screenshot'];
// Handle different path formats from Stash
if (strpos($screenshotPath, 'http') === 0) {
// Already a full URL
$screenshotUrl = $screenshotPath;
} elseif (strpos($screenshotPath, '/') === 0) {
// Absolute path from Stash root
$screenshotUrl = "{$this->baseUrl}" . $screenshotPath;
} else {
// Relative path - assume it's in a standard location
$screenshotUrl = "{$this->baseUrl}/scene/" . $sceneData['id'] . "/" . $screenshotPath;
}
$this->logProgress("Screenshot URL: " . $screenshotUrl);
}
// For cover, we might need to use a different approach or check if there's a primary image
// For now, we'll use the screenshot as cover if available
// For cover, we'll use the screenshot as cover if available
if ($screenshotUrl) {
$coverUrl = $screenshotUrl;
}
@@ -297,6 +314,9 @@ class StashSyncService extends BaseSyncService
$localCoverPath = $this->imageDownloader->downloadImage($coverUrl, $coverFilename, 'adult_videos');
if ($localCoverPath) {
$sceneData['local_cover_path'] = $this->imageDownloader->getPublicUrl($localCoverPath);
$this->logProgress("Downloaded cover: " . $localCoverPath);
} else {
$this->logProgress("Failed to download cover from: " . $coverUrl);
}
}
@@ -305,6 +325,9 @@ class StashSyncService extends BaseSyncService
$localScreenshotPath = $this->imageDownloader->downloadImage($screenshotUrl, $screenshotFilename, 'adult_videos');
if ($localScreenshotPath) {
$sceneData['local_screenshot_path'] = $this->imageDownloader->getPublicUrl($localScreenshotPath);
$this->logProgress("Downloaded screenshot: " . $localScreenshotPath);
} else {
$this->logProgress("Failed to download screenshot from: " . $screenshotUrl);
}
}
@@ -434,11 +457,26 @@ class StashSyncService extends BaseSyncService
// Try to download performer image if available
$thumbnailPath = null;
if ($imagePath) {
$imageUrl = "{$this->baseUrl}/" . ltrim($imagePath, '/');
// Handle different image path formats from Stash
if (strpos($imagePath, 'http') === 0) {
// Already a full URL
$imageUrl = $imagePath;
} elseif (strpos($imagePath, '/') === 0) {
// Absolute path from Stash root
$imageUrl = "{$this->baseUrl}" . $imagePath;
} else {
// Relative path - assume it's in performer images directory
$imageUrl = "{$this->baseUrl}/performer/" . $imagePath;
}
$this->logProgress("Performer image URL for {$name}: " . $imageUrl);
$thumbnailFilename = $this->imageDownloader->generateFilename($imageUrl, 'actor');
$localImagePath = $this->imageDownloader->downloadImage($imageUrl, $thumbnailFilename, 'actors');
if ($localImagePath) {
$thumbnailPath = $this->imageDownloader->getPublicUrl($localImagePath);
$this->logProgress("Downloaded performer image: " . $localImagePath);
} else {
$this->logProgress("Failed to download performer image from: " . $imageUrl);
}
}