Skip to content

Commit

Permalink
Fix bug in getSeries by taking advantage of v3 features of the Flysytem.
Browse files Browse the repository at this point in the history
  • Loading branch information
geneowak committed Dec 13, 2024
1 parent 7913b04 commit 775b7ef
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions App/System/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use App\Utils\Utils;
use League\Flysystem\Filesystem;
use League\Flysystem\StorageAttributes;

/**
* Class Controller
Expand All @@ -29,23 +30,26 @@ public function __construct(
*/
public function getSeries(bool $skip = false): array
{
$list = $this->system->listContents(SERIES_FOLDER, true);
$array = [];
// we want only files, and we only need their paths
$list = $this->system->listContents(SERIES_FOLDER, true)
->filter(fn (StorageAttributes $attributes) => $attributes->isFile())
->sortByPath()
->map(fn (StorageAttributes $attrs) => $attrs->path())
->toArray();

foreach ($list as $entry) {
if ($entry['type'] != 'file') {
continue;
}
$array = [];

//skip folder, we only want the files
if (str_starts_with((string) $entry['filename'], '._')) {
foreach ($list as $path) {
$dirAndFilename = explode('/', substr((string) $path, strlen(SERIES_FOLDER) + 1));
$serie = $dirAndFilename[0];
// this happens on mac when "series/.DS_Store" is present
if (! isset($dirAndFilename[1])) {
continue;
}
$episodeName = $dirAndFilename[1];
$episodeNo = (int) substr((string) $episodeName, 0, strpos((string) $episodeName, '-'));

$serie = substr((string) $entry['dirname'], strlen(SERIES_FOLDER) + 1);
$episode = (int) substr((string) $entry['filename'], 0, strpos((string) $entry['filename'], '-'));

$array[$serie][] = $episode;
$array[$serie][] = $episodeNo;
}

// TODO: #Issue# returns array with index 0
Expand Down

0 comments on commit 775b7ef

Please sign in to comment.