diff --git a/admin.php b/admin.php index d8b1eb3..6c00575 100644 --- a/admin.php +++ b/admin.php @@ -21,10 +21,11 @@ declare(strict_types=1); require_once('include/getJsonErrorString.php'); -//const FOLDER_PATH = '../video/unwatched'; -const FOLDER_PATH = '../video/tv.shows/Archer'; +const FOLDER_PATH = '../video/unwatched'; +//const FOLDER_PATH = '../video/tv.shows/Archer'; const MAX_RECURSE_DEPTH = 5; $g_errors = []; +$g_debug = []; class path_entry @@ -42,16 +43,19 @@ class path_entry function guessMediaType($filename) : string { + global $g_errors, $g_debug; + $matches = []; $current_year = getdate()['year']; - if (false !== stristr($filename, 'season')) { + if (preg_match('/season?[0-9]{2}/i', $filename)) { return 'tv_show'; } else if (preg_match('/s[0-9]{2}/i', $filename)) { return 'tv_show'; - // TODO: this will only match the first 4 digit number in the string - } else if (preg_match('/[0-9]{4}/', $filename, $match)) { - if ((int) $match[0] >= 1878 && (int) $match[0] <= $current_year) - return 'movie'; + } else if (preg_match_all('/[0-9]{4}/', $filename, $matches)) { + foreach ($matches[0] as $match) { + if ((int) $match >= 1878 && (int) $match <= $current_year) + return 'movie'; + } } return 'unknown'; @@ -125,7 +129,7 @@ function unsetParentReferences(&$path_entry) : void function getUnsavedMetadata() : void { $path_info = getPathEntry(FOLDER_PATH); - global $g_errors; + global $g_errors, $g_debug; $out = new StdClass(); header('Content-Type: text/json'); @@ -134,6 +138,7 @@ function getUnsavedMetadata() : void unsetParentReferences($path_info); // NOTE: don't encode parent references $out->mem_usage = memory_get_peak_usage(); $out->path_info = $path_info; + $out->debug = $g_debug; $json = json_encode($out); if ($json) { diff --git a/query_page.php b/query_page.php index 4b6638b..9a843e0 100644 --- a/query_page.php +++ b/query_page.php @@ -52,8 +52,13 @@ function main(&$local_cache, &$tmdb_interface, &$cache_results, &$is_cached, $qu if (!$is_cached) { $parsed = $tmdb_interface->query('search/movie', $key, $query_str); - if (!$tmdb_interface->errors && $parsed) + if ($tmdb_interface->errors) { + foreach ($tmdb_interface->errors as $err) { + error_log(__FILE__ . " , " . __FUNCTION__ . " , $err"); + } + } else if ($parsed) { $cache_results = $local_cache->insert_query_cache($query_str, $parsed); + } } }