Fetch season and episode from file tags

This commit is contained in:
Dan Jones 2022-12-06 11:29:17 -06:00
commit a148fd32d7

View file

@ -2,6 +2,7 @@
namespace App\Data\DataPipes;
use FFMpeg\FFMpeg;
use Illuminate\Support\Collection;
use SimpleXMLElement;
use Spatie\LaravelData\DataPipes\DataPipe;
@ -26,7 +27,7 @@ class GetSeasonEp implements DataPipe
return $this->getEpFromNfo($properties, $nfo);
}
return $properties;
return $this->getEpFromFfprobe($properties);
}
protected function getEpFromNfo(Collection $properties, string $nfo): Collection
@ -41,4 +42,21 @@ class GetSeasonEp implements DataPipe
return $properties;
}
protected function getEpFromFfprobe(Collection $properties): Collection
{
$ffmpeg = FFMpeg::create();
$ffprobe = $ffmpeg->getFFProbe();
$tags = $ffprobe->format($properties->get('path'))->get('tags');
if ($season = $tags['season_number'] ?? $tags['SEASON_NUMBER'] ?? null) {
$properties['season'] = (int) $season;
}
if ($episode = $tags['episode_sort'] ?? $tags['EPISODE_SORT'] ?? null) {
$properties['episode'] = (int) $episode;
}
return $properties;
}
}