episode.php 785 B

1234567891011121314151617181920212223242526272829303132333435
  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. die('Unable to opendir(): ' . htmlspecialchars($season_path) . "\n");
  10. }
  11. while (false !== ($episode = readdir($dir))) {
  12. # Skip junk
  13. if (isJunk($episode)) {
  14. continue;
  15. }
  16. # Record the episode number
  17. if (preg_match('/^(?:S\d+E)?(\d+)\s*\-\s*(\S.*\.\w{2,4})$/i', $episode, $matches)) {
  18. $episode_num = intval($matches[1]);
  19. $retval[ $episode_num ] = $matches[2];
  20. }
  21. }
  22. closedir($dir);
  23. # Sort numerically; the directory listing typically returns a lexicographic order
  24. ksort($retval, SORT_NUMERIC);
  25. return $retval;
  26. }
  27. ?>