getMySocket()->getContent($url); if (!$response) { throw new \Exception("getCrawler 실패:{$url}"); } $crawler = new Crawler($response); return $crawler->filter($tag); } final protected function getNodes(Crawler $crawler, array $options, $nodes = []): array { $crawler->filter($options["tag"])->each( function (Crawler $node) use (&$options, &$nodes): void { log_message("debug", sprintf("getNode-> %s", $options["tag"])); $nodes[] = $node; } ); return $nodes; } protected function getMediaTag(string $mediaType): string { $mediaTag = ""; switch ($mediaType) { case "image": $mediaTag = sprintf( "\"%s\"", $this->getMyStorage()->getUploadPath(), $this->getMyStorage()->getEntity()->getPath(), $this->getMyStorage()->getEntity()->getTitle(), $this->getMyStorage()->getEntity()->getTitle() ); break; case "video": $mediaTag = sprintf( "", $this->getMyStorage()->getEntity()->getTitle(), $this->getMyStorage()->getUploadPath(), $this->getMyStorage()->getEntity()->getPath(), $this->getMyStorage()->getEntity()->getTitle(), $this->getMyStorage()->getEntity()->getMimeType(), ); break; } return $mediaTag; } final protected function download(Crawler $crawler, array $options): array { $downloadInfos = []; $nodes = $this->getNodes($crawler, $options); foreach ($nodes as $node) { $url = $node->attr($options["attr"]); $downloadInfos[] = $this->getMySocket()->download($url); } return $downloadInfos; } protected function save(string $mediaType, array $downloadInfos, $fileEntitys = []): array { foreach ($downloadInfos as $downloadInfo) { $entity = $this->getMyStorage()->getEntity(); $entity->setTitle($downloadInfo['fileName']); if (!$this->getMyStorage()->save($downloadInfo['content'])) { continue; } $entity->setMediaHTML($this->getMediaTag($mediaType)); $fileEntitys[] = $entity; } return $fileEntitys; } }