season.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?
  2. require 'config.php';
  3. # True if the provided season folder is being monitored
  4. function isMonitored($season_path) {
  5. if (file_exists(dirname($season_path) . '/skip')) {
  6. return false;
  7. }
  8. if (file_exists($season_path . '/season_done')) {
  9. return false;
  10. }
  11. $season = 0;
  12. if (preg_match('/^Season\s+(\d+)$/i', basename($season_path), $matches)) {
  13. $season = $matches[1];
  14. }
  15. if (!$season) {
  16. return false;
  17. }
  18. return true;
  19. }
  20. # Get the season search status, including the URL (if any) for the provided path
  21. function seasonSearch($season_path) {
  22. $retval = isMonitored($season_path);
  23. if ($retval) {
  24. $file = $season_path . '/url';
  25. if (is_readable($file)) {
  26. $retval = trim(file_get_contents($file));
  27. }
  28. }
  29. return $retval;
  30. }
  31. # Find all the season in a provided series folder and determine which are being monitored
  32. function findSeasons($path) {
  33. $retval = array();
  34. # Check for the skip file
  35. $skip = false;
  36. if (file_exists($path . '/skip')) {
  37. $skip = true;
  38. }
  39. $dir = opendir($path);
  40. if ($dir === FALSE) {
  41. die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
  42. }
  43. while (false !== ($season = readdir($dir))) {
  44. # Skip junk
  45. if (isJunk($show)) {
  46. continue;
  47. }
  48. # We only care about directories
  49. $season_path = $path . '/' . $season;
  50. if (!is_dir($season_path)) {
  51. continue;
  52. }
  53. # Record the season number and search status
  54. if (preg_match('/Season\s+(\d+)/i', $season, $matches)) {
  55. $retval[ $matches[1] ] = seasonSearch($season_path);
  56. }
  57. }
  58. closedir($dir);
  59. # Sort numerically; the directory listing typically returns a lexicographic order
  60. ksort($retval, SORT_NUMERIC);
  61. return $retval;
  62. }
  63. # Save the search status for all seasons in a series
  64. function saveSeasons($data) {
  65. }
  66. # Add a folder for the provided show and season
  67. function addSeason($show, $season) {
  68. global $TV_DIR;
  69. # Ensure the show exists
  70. $show_path = $TV_DIR . '/' . $show;
  71. if (!is_dir($show_path)) {
  72. die('Invalid show: ' . htmlspecialchars($show) . "\n");
  73. }
  74. # Ensure the season does not exist
  75. $season_path = $show_path . '/Season ' . intval($season);
  76. if (file_exists($season_path)) {
  77. die('Invalid season: ' . htmlspecialchars($season) . "\n");
  78. }
  79. # Create the directory
  80. mkdir($season_path);
  81. }
  82. ?>