mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
// Load environment variables
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
|
$dotenv->load();
|
|
|
|
// Load database configuration
|
|
$dbConfig = require __DIR__ . '/config/database.php';
|
|
\App\Database\Database::setConfig($dbConfig);
|
|
|
|
// Initialize database
|
|
try {
|
|
$pdo = \App\Database\Database::getInstance();
|
|
echo "✅ Database connection successful\n";
|
|
} catch (Exception $e) {
|
|
die('❌ Database connection failed: ' . $e->getMessage());
|
|
}
|
|
|
|
// Check if tables exist
|
|
try {
|
|
$tables = ['sources', 'movies', 'sync_logs', 'games'];
|
|
foreach ($tables as $table) {
|
|
$stmt = $pdo->query("SHOW TABLES LIKE '{$table}'");
|
|
if ($stmt->rowCount() > 0) {
|
|
echo "✅ Table '{$table}' exists\n";
|
|
} else {
|
|
echo "❌ Table '{$table}' does not exist\n";
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "❌ Error checking tables: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
// Test Jellyfin connectivity (if configured)
|
|
echo "\n🔍 Testing Jellyfin connectivity...\n";
|
|
try {
|
|
$sourceModel = new \App\Models\Source($pdo);
|
|
$sources = $sourceModel->findAll(['name' => 'jellyfin']);
|
|
|
|
if (empty($sources)) {
|
|
echo "❌ No Jellyfin source configured\n";
|
|
exit;
|
|
}
|
|
|
|
$jellyfinSource = $sources[0];
|
|
echo "✅ Found Jellyfin source: {$jellyfinSource['display_name']}\n";
|
|
|
|
if (empty($jellyfinSource['api_key']) || empty($jellyfinSource['api_url'])) {
|
|
echo "❌ Jellyfin API key or URL not configured\n";
|
|
exit;
|
|
}
|
|
|
|
// Test HTTP connection to Jellyfin
|
|
$client = new GuzzleHttp\Client(['timeout' => 10]);
|
|
$url = rtrim($jellyfinSource['api_url'], '/') . '/Users';
|
|
|
|
echo "🔗 Testing connection to: {$url}\n";
|
|
|
|
$response = $client->get($url, [
|
|
'headers' => [
|
|
'X-MediaBrowser-Token' => $jellyfinSource['api_key'],
|
|
'User-Agent' => 'MediaCollector-Test/1.0'
|
|
]
|
|
]);
|
|
|
|
$httpCode = $response->getStatusCode();
|
|
echo "✅ HTTP Response: {$httpCode}\n";
|
|
|
|
if ($httpCode === 200) {
|
|
$data = json_decode($response->getBody(), true);
|
|
$userCount = count($data);
|
|
echo "✅ Found {$userCount} users in Jellyfin\n";
|
|
|
|
if ($userCount > 0) {
|
|
$userId = $data[0]['Id'];
|
|
echo "✅ Using user ID: {$userId}\n";
|
|
|
|
// Test getting movies
|
|
$moviesUrl = rtrim($jellyfinSource['api_url'], '/') . "/Users/{$userId}/Items";
|
|
echo "🔗 Testing movies endpoint: {$moviesUrl}\n";
|
|
|
|
$moviesResponse = $client->get($moviesUrl, [
|
|
'headers' => [
|
|
'X-MediaBrowser-Token' => $jellyfinSource['api_key'],
|
|
'User-Agent' => 'MediaCollector-Test/1.0'
|
|
],
|
|
'query' => [
|
|
'IncludeItemTypes' => 'Movie',
|
|
'Recursive' => 'true',
|
|
'Fields' => 'ProviderIds,Overview,PremiereDate,CommunityRating'
|
|
]
|
|
]);
|
|
|
|
$moviesHttpCode = $moviesResponse->getStatusCode();
|
|
echo "✅ Movies HTTP Response: {$moviesHttpCode}\n";
|
|
|
|
if ($moviesHttpCode === 200) {
|
|
$moviesData = json_decode($moviesResponse->getBody(), true);
|
|
$movieCount = count($moviesData['Items'] ?? []);
|
|
echo "✅ Found {$movieCount} movies in Jellyfin library\n";
|
|
} else {
|
|
echo "❌ Failed to fetch movies from Jellyfin\n";
|
|
}
|
|
}
|
|
} else {
|
|
echo "❌ Jellyfin API returned HTTP {$httpCode}\n";
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "❌ Jellyfin connectivity test failed: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
echo "\n✨ Test completed!\n";
|