series.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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($series_path, $data, $series_last, $seasons_last) {
  56. global $EXISTS_FILES;
  57. global $CONTENT_FILES;
  58. # Exists files
  59. foreach ($EXISTS_FILES as $file) {
  60. $path = $series_path . '/' . $file;
  61. if ($data[ $file ]) {
  62. if (!file_exists($path)) {
  63. touch($path);
  64. }
  65. } else {
  66. if (file_exists($path)) {
  67. unlink($path);
  68. }
  69. }
  70. }
  71. # Content files
  72. foreach ($CONTENT_FILES as $file) {
  73. $path = $series_path . '/' . $file;
  74. if ($data[ $file ]) {
  75. file_put_contents($path, $data[ $file ]);
  76. } else {
  77. if (file_exists($path)) {
  78. unlink($path);
  79. }
  80. }
  81. }
  82. }
  83. # Add a series as identified by TVDB ID
  84. function addSeries($id) {
  85. }
  86. ?>