debug_jellystat_metadata.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Debug script to test JellyStat metadata functionality
  4. * Run this to troubleshoot why metadata returns "Unknown Item"
  5. */
  6. require_once 'api/config/config.php';
  7. require_once 'api/classes/organizr.php';
  8. // Create Organizr instance (this will load config)
  9. $organizr = new Organizr();
  10. echo "=== JellyStat Metadata Debug Tool ===\n\n";
  11. // Check configuration
  12. $jellyStatURL = $organizr->config['jellyStatURL'] ?? '';
  13. $jellyStatInternalURL = $organizr->config['jellyStatInternalURL'] ?? '';
  14. $jellyStatApikey = $organizr->config['jellyStatApikey'] ?? '';
  15. $enabled = $organizr->config['homepageJellyStatEnabled'] ?? false;
  16. echo "Configuration:\n";
  17. echo "- JellyStat URL: " . ($jellyStatURL ?: 'NOT SET') . "\n";
  18. echo "- Internal URL: " . ($jellyStatInternalURL ?: 'NOT SET') . "\n";
  19. echo "- API Key: " . ($jellyStatApikey ? 'SET (****)' : 'NOT SET') . "\n";
  20. echo "- Plugin Enabled: " . ($enabled ? 'YES' : 'NO') . "\n\n";
  21. if (!$enabled) {
  22. echo "❌ JellyStat plugin is not enabled!\n";
  23. echo "Enable it in Organizr settings first.\n";
  24. exit(1);
  25. }
  26. if (!$jellyStatURL) {
  27. echo "❌ JellyStat URL is not configured!\n";
  28. echo "Set jellyStatURL in Organizr settings first.\n";
  29. exit(1);
  30. }
  31. // Test basic connectivity
  32. $testUrl = !empty($jellyStatInternalURL) ? $jellyStatInternalURL : $jellyStatURL;
  33. $testUrl = rtrim($organizr->qualifyURL($testUrl), '/');
  34. echo "Testing connectivity to: {$testUrl}\n\n";
  35. // Test endpoints that the metadata function would try
  36. $testKey = 'test-item-id';
  37. $endpoints = [];
  38. if ($jellyStatApikey) {
  39. $endpoints['JellyStat API (getItem)'] = $testUrl . '/api/getItem?apiKey=' . urlencode($jellyStatApikey) . '&id=' . urlencode($testKey);
  40. $endpoints['JellyStat API (getItemById)'] = $testUrl . '/api/getItemById?apiKey=' . urlencode($jellyStatApikey) . '&id=' . urlencode($testKey);
  41. }
  42. $endpoints['Jellyfin Proxy (basic)'] = $testUrl . '/proxy/Items/' . rawurlencode($testKey);
  43. $endpoints['Jellyfin Proxy (with fields)'] = $testUrl . '/proxy/Items/' . rawurlencode($testKey) . '?Fields=Overview,People,Genres,CommunityRating,CriticRating,Studios,Taglines,ProductionYear,PremiereDate';
  44. // Also test a real item ID if provided via command line
  45. if (isset($argv[1])) {
  46. $realKey = $argv[1];
  47. echo "Testing with real item ID: {$realKey}\n\n";
  48. if ($jellyStatApikey) {
  49. $endpoints['Real Item - JellyStat API'] = $testUrl . '/api/getItem?apiKey=' . urlencode($jellyStatApikey) . '&id=' . urlencode($realKey);
  50. }
  51. $endpoints['Real Item - Jellyfin Proxy'] = $testUrl . '/proxy/Items/' . rawurlencode($realKey) . '?Fields=Overview,People,Genres,CommunityRating,CriticRating,Studios,Taglines,ProductionYear,PremiereDate';
  52. }
  53. foreach ($endpoints as $name => $url) {
  54. echo "Testing {$name}:\n";
  55. echo "URL: {$url}\n";
  56. try {
  57. $options = $organizr->requestOptions($url, null,
  58. $organizr->config['jellyStatDisableCertCheck'] ?? false,
  59. $organizr->config['jellyStatUseCustomCertificate'] ?? false
  60. );
  61. $response = Requests::get($url, [], $options);
  62. if ($response->success) {
  63. $data = json_decode($response->body, true);
  64. if (json_last_error() === JSON_ERROR_NONE) {
  65. echo "✅ SUCCESS - Status: {$response->status_code}\n";
  66. if (is_array($data)) {
  67. $keys = array_keys($data);
  68. echo "Response has keys: " . implode(', ', array_slice($keys, 0, 10)) .
  69. (count($keys) > 10 ? '... (' . count($keys) . ' total)' : '') . "\n";
  70. // Look for typical media metadata fields
  71. $mediaFields = ['Name', 'Id', 'Type', 'Overview', 'Genres', 'People', 'RunTimeTicks', 'ProductionYear'];
  72. $foundFields = array_intersect($keys, $mediaFields);
  73. if (!empty($foundFields)) {
  74. echo "Media fields found: " . implode(', ', $foundFields) . "\n";
  75. // Show sample values
  76. foreach (['Name', 'Type', 'Overview'] as $field) {
  77. if (isset($data[$field])) {
  78. $value = $data[$field];
  79. if (is_string($value) && strlen($value) > 50) {
  80. $value = substr($value, 0, 47) . '...';
  81. }
  82. echo "{$field}: {$value}\n";
  83. }
  84. }
  85. }
  86. } else {
  87. echo "Response is not an array: " . gettype($data) . "\n";
  88. }
  89. } else {
  90. echo "❌ Invalid JSON response\n";
  91. echo "Raw response: " . substr($response->body, 0, 200) . "...\n";
  92. }
  93. } else {
  94. echo "❌ HTTP Error: {$response->status_code}\n";
  95. if (!empty($response->body)) {
  96. echo "Error body: " . substr($response->body, 0, 200) . "...\n";
  97. }
  98. }
  99. } catch (Exception $e) {
  100. echo "❌ Exception: " . $e->getMessage() . "\n";
  101. }
  102. echo "\n" . str_repeat('-', 60) . "\n\n";
  103. }
  104. echo "=== Debug Complete ===\n\n";
  105. echo "Next steps if endpoints are failing:\n";
  106. echo "1. Verify JellyStat is running and accessible\n";
  107. echo "2. Check if API key is correct and has permissions\n";
  108. echo "3. Test URLs directly in browser/curl\n";
  109. echo "4. Check JellyStat logs for errors\n";
  110. echo "5. Verify firewall/network connectivity\n\n";
  111. echo "If you have a working item ID from JellyStat, run:\n";
  112. echo "php debug_jellystat_metadata.php YOUR-ITEM-ID\n";