episode.php 1013 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?
  2. require 'config.php';
  3. # Find all the episodes in a provided season folder
  4. function findEpisodes($series, $season) {
  5. $retval = array();
  6. $season_path = seasonPath($series, $season);
  7. $dir = @opendir($season_path);
  8. if ($dir === FALSE) {
  9. echo 'Unable to opendir(): ' . htmlspecialchars($season_path) . "\n";
  10. return false;
  11. }
  12. while (false !== ($episode = readdir($dir))) {
  13. # Skip junk
  14. if (isJunk($episode)) {
  15. continue;
  16. }
  17. # Record the episode number
  18. if (preg_match('/^(20\d\d)\-(\d\d)\-(\d\d)\s*\-\s*(\S.*\.\w{2,4})$/i', $episode, $matches)) {
  19. $episode_num = intval($matches[1] . $matches[2] . $matches[3]);
  20. $retval[ $episode_num ] = $matches[4];
  21. } elseif (preg_match('/^(?:S\d+E)?(\d+)\s*\-\s*(\S.*\.\w{2,4})$/i', $episode, $matches)) {
  22. $episode_num = intval($matches[1]);
  23. $retval[ $episode_num ] = $matches[2];
  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. ?>