fix: moves monitor logic into own directory
This commit is contained in:
76
src/Monitor/Service/MediaFiles.php
Normal file
76
src/Monitor/Service/MediaFiles.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Monitor\Service;
|
||||
|
||||
use Aimeos\Map;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class MediaFiles
|
||||
{
|
||||
private Finder $finder;
|
||||
|
||||
private string $moviesPath;
|
||||
|
||||
private string $tvShowsPath;
|
||||
|
||||
public function __construct(
|
||||
#[Autowire(param: 'media.movies_path')]
|
||||
string $moviesPath,
|
||||
|
||||
#[Autowire(param: 'media.tvshows_path')]
|
||||
string $tvShowsPath,
|
||||
) {
|
||||
$this->finder = new Finder();
|
||||
$this->moviesPath = $moviesPath;
|
||||
$this->tvShowsPath = $tvShowsPath;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach ($this->finder->in($path)->files() as $file) {
|
||||
if ($onlyFilenames) {
|
||||
$results[] = $file->getRelativePathname();
|
||||
} else {
|
||||
$results[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
return Map::from($results);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user