series.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?
  2. require 'config.php';
  3. # Find all shows under the given path
  4. function allShows($base) {
  5. $retval = array();
  6. # Look for series folders
  7. $tv_dir = opendir($base);
  8. if ($tv_dir === FALSE) {
  9. die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
  10. }
  11. while (false !== ($show = readdir($tv_dir))) {
  12. # Skip junk
  13. if (isJunk($show)) {
  14. continue;
  15. }
  16. # We only care about directories
  17. $show_path = $base . '/' . $show;
  18. if (!is_dir($show_path)) {
  19. continue;
  20. }
  21. # Record the show title and look for season folders
  22. $retval[ $show ] = findSeasons($show_path);
  23. }
  24. closedir($tv_dir);
  25. return $retval;
  26. }
  27. # Read and parse all of the series-level exists, content, and *.webloc files
  28. function readFlags($path) {
  29. global $EXISTS_FILES;
  30. global $CONTENT_FILES;
  31. $flags = array();
  32. # Look for all the exists files
  33. foreach ($EXISTS_FILES as $name) {
  34. $flags[ $name ] = false;
  35. if (file_exists($path . '/' . $name)) {
  36. $flags[ $name ] = true;
  37. }
  38. }
  39. # Read all the content files
  40. foreach ($CONTENT_FILES as $name) {
  41. $flags[ $name ] = false;
  42. $file = $path . '/' . $name;
  43. if (is_readable($file)) {
  44. $flags[ $name ] = trim(file_get_contents($file));
  45. }
  46. }
  47. # Read the TVDB IDs from the *.webloc file
  48. $webloc = findWebloc($path);
  49. if ($webloc !== false) {
  50. $flags = array_merge($flags, readWebloc($webloc));
  51. }
  52. return $flags;
  53. }
  54. # Parse and save all of the serires-level exists and content files
  55. function saveFlags($show, $data) {
  56. global $TV_PATH;
  57. global $EXISTS_FILES;
  58. global $CONTENT_FILES;
  59. $series_path = $TV_PATH . '/' . $show;
  60. # Exists files
  61. foreach ($EXISTS_FILES as $file) {
  62. $path = $series_path . '/' . $file;
  63. if ($data[ $file ]) {
  64. if (!file_exists($path)) {
  65. touch($path);
  66. }
  67. } else {
  68. if (file_exists($path)) {
  69. unlink($path);
  70. }
  71. }
  72. }
  73. # Content files
  74. foreach ($CONTENT_FILES as $file) {
  75. $path = $series_path . '/' . $file;
  76. if ($data[ $file ]) {
  77. file_put_contents($path, $data[ $file ]);
  78. } else {
  79. if (file_exists($path)) {
  80. unlink($path);
  81. }
  82. }
  83. }
  84. }
  85. # Add a series as identified by TVDB ID
  86. function addSeries($id) {
  87. }
  88. ?>