series.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?
  2. require 'config.php';
  3. function seriesExists($series) {
  4. return is_dir(seriesPath($series));
  5. }
  6. function seriesPath($series) {
  7. global $TV_PATH;
  8. return $TV_PATH . '/' . $series;
  9. }
  10. # Find all seriess under the given path
  11. function allSeries($base) {
  12. $retval = array();
  13. # Look for series folders
  14. $tv_dir = opendir($base);
  15. if ($tv_dir === FALSE) {
  16. die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
  17. }
  18. while (false !== ($series = readdir($tv_dir))) {
  19. # Skip junk
  20. if (isJunk($series)) {
  21. continue;
  22. }
  23. # Ensure the series is reasonable
  24. if (!seriesExists($series)) {
  25. continue;
  26. }
  27. # Record the series title and look for season folders
  28. $retval[ $series ] = findSeasons($series);
  29. }
  30. closedir($tv_dir);
  31. return $retval;
  32. }
  33. # Read and parse all of the series-level exists, content, and *.webloc files
  34. function readFlags($series) {
  35. global $EXISTS_FILES;
  36. global $CONTENT_FILES;
  37. $flags = array();
  38. # Ensure the series exists
  39. if (!seriesExists($series)) {
  40. die('Invalid series: ' . htmlspecialchars($series) . "\n");
  41. }
  42. $path = seriesPath($series);
  43. # Look for all the exists files
  44. foreach ($EXISTS_FILES as $name) {
  45. $flags[ $name ] = false;
  46. if (file_exists($path . '/' . $name)) {
  47. $flags[ $name ] = true;
  48. }
  49. }
  50. # Read all the content files
  51. foreach ($CONTENT_FILES as $name) {
  52. $flags[ $name ] = false;
  53. $file = $path . '/' . $name;
  54. if (is_readable($file)) {
  55. $flags[ $name ] = trim(file_get_contents($file));
  56. }
  57. }
  58. # Read the TVDB IDs from the *.webloc file
  59. $webloc = findWebloc($path);
  60. if ($webloc !== false) {
  61. $flags = array_merge($flags, readWebloc($webloc));
  62. }
  63. return $flags;
  64. }
  65. # Parse and save all of the serires-level exists and content files
  66. function saveFlags($series, $data, $series_last, $seasons_last) {
  67. global $EXISTS_FILES;
  68. global $CONTENT_FILES;
  69. # Ensure the series exists
  70. if (!seriesExists($series)) {
  71. die('Invalid series: ' . htmlspecialchars($series) . "\n");
  72. }
  73. $series_path = seriesPath($series);
  74. # Special handling for "skip"
  75. {
  76. $path = $series_path . '/skip';
  77. if ($data['skip']) {
  78. if (!file_exists($path)) {
  79. touch($path);
  80. }
  81. } else {
  82. if (file_exists($path)) {
  83. unlink($path);
  84. }
  85. }
  86. }
  87. # Ignore everything else if we are now or were just in "skip" mode
  88. if ($series_last['skip'] || $data['skip']) {
  89. return;
  90. }
  91. # Exists files
  92. foreach ($EXISTS_FILES as $file) {
  93. $path = $series_path . '/' . $file;
  94. if ($data[ $file ]) {
  95. if (!file_exists($path)) {
  96. touch($path);
  97. }
  98. } else {
  99. if (file_exists($path)) {
  100. unlink($path);
  101. }
  102. }
  103. }
  104. # Content files
  105. foreach ($CONTENT_FILES as $file) {
  106. $path = $series_path . '/' . $file;
  107. if ($data[ $file ]) {
  108. file_put_contents($path, $data[ $file ]);
  109. } else {
  110. if (file_exists($path)) {
  111. unlink($path);
  112. }
  113. }
  114. }
  115. }
  116. # Add a series as identified by TVDB ID
  117. function addSeries($id) {
  118. }
  119. ?>