finder = new Finder(); $this->moviesPath = $moviesPath; $this->tvShowsPath = $tvShowsPath; $this->filesystem = $filesystem; } public function getPathByType(string $mediaType): string { if ('movies' === $mediaType) { return $this->moviesPath; } elseif ('tvshows' === $mediaType) { return $this->tvShowsPath; } throw new \Exception(sprintf('A path for media type %s does not exist.', $mediaType)); } public function getMoviesPath(): string { return $this->moviesPath; } public function getTvShowsPath(): string { return $this->tvShowsPath; } public function getMovieDirs(): Map { $results = []; foreach ($this->finder->in($this->moviesPath)->directories() as $file) { $results[] = $file; } return Map::from($results); } public function getTvShowDirs(): Map { $results = []; foreach ($this->finder->in($this->tvShowsPath)->directories() as $file) { $results[] = $file; } return Map::from($results); } public function getEpisodes(string $path, bool $onlyFilenames = true): Map { if (!str_starts_with($path, $this->tvShowsPath)) { $path = $this->tvShowsPath . DIRECTORY_SEPARATOR . $path; } if (false === $this->filesystem->exists($path)) { $this->filesystem->mkdir($path); } $results = []; foreach ($this->finder->in($path)->files() as $file) { if ($onlyFilenames) { $results[] = $file->getRelativePathname(); } else { $results[] = $file; } } return Map::from($results); } public function createMovieDirectory(string $path): string { $path = $this->moviesPath . DIRECTORY_SEPARATOR . $path; if (false === $this->filesystem->exists($path)) { $this->filesystem->mkdir($path); } return $path; } public function createTvShowDirectory(string $path): string { $path = $this->tvShowsPath . DIRECTORY_SEPARATOR . $path; if (false === $this->filesystem->exists($path)) { $this->filesystem->mkdir($path); } return $path; } public function createDirectory(string $path): string { if (false === $this->filesystem->exists($path)) { $this->filesystem->mkdir($path); } return $path; } }