episode.php 842 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?
  2. require 'config.php';
  3. # Find all the episodes in a provided season folder
  4. function findEpisodes($season_path) {
  5. $retval = array();
  6. $dir = opendir($season_path);
  7. if ($dir === FALSE) {
  8. die('Unable to opendir(): ' . htmlspecialchars($season_path) . "\n");
  9. }
  10. while (false !== ($episode = readdir($dir))) {
  11. # Skip junk
  12. if (isJunk($episode)) {
  13. continue;
  14. }
  15. # We only care about files
  16. $episode_path = $path . '/' . $episode;
  17. if (!is_file($episode_path)) {
  18. continue;
  19. }
  20. # Record the episode number
  21. if (preg_match('/^(?:S\d+E)?(\d+)\s*\-\s*\.\w\w\w$/i', $season, $matches)) {
  22. $episode_num = intval($matches[1]);
  23. $retval[ $episode_num ] = true;
  24. }
  25. }
  26. closedir($dir);
  27. # Sort numerically; the directory listing typically returns a lexicographic order
  28. ksort($retval, SORT_NUMERIC);
  29. return $retval;
  30. }
  31. ?>