path) && $this->checksum === md5_file($this->path); } public static function retrieveForEpisode(Episode $episode): ?self { return Cache::get("episode-playable.$episode->id"); } public static function createForEpisode(Episode $episode): self { $dir = sys_get_temp_dir() . '/koel-episodes'; $file = sprintf('%s/%s.mp3', $dir, $episode->id); if (!File::exists($file)) { File::ensureDirectoryExists($dir); Http::sink($file)->get($episode->path)->throw(); } $playable = new self($file, md5_file($file)); Cache::forever("episode-playable.$episode->id", $playable); return $playable; } /** @inheritDoc */ public function toArray(): array { return [ 'path' => $this->path, 'checksum' => $this->checksum, ]; } /** @inheritDoc */ public function toJson($options = 0): string { return json_encode($this->toArray(), $options); } }