| Conditions | 4 |
| Paths | 17 |
| Total Lines | 31 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | public function process(Video $video): void |
||
| 26 | { |
||
| 27 | if ($video->getType()->getValue() !== VideoType::TYPE_YOUTUBE) { |
||
| 28 | throw new \InvalidArgumentException(); |
||
| 29 | } |
||
| 30 | |||
| 31 | try { |
||
| 32 | $response = $this->youtubeProvider->getVideo($video->getVideoId()); |
||
| 33 | if (count($response->getItems()) > 0) { |
||
| 34 | $youtubeVideo = $response->getItems()[0]; |
||
| 35 | |||
| 36 | $snippet = $youtubeVideo->getSnippet(); |
||
| 37 | $video->setTitle($snippet->getTitle()); |
||
| 38 | echo $video->getId() . "\n"; |
||
| 39 | //var_dump($snippet->getThumbnails()); |
||
| 40 | $video->setThumbnail( |
||
| 41 | $snippet->getThumbnails() |
||
| 42 | ->getHigh() |
||
| 43 | ->getUrl() |
||
| 44 | ); |
||
| 45 | |||
| 46 | $video->setDescription($snippet->getDescription()); |
||
| 47 | |||
| 48 | $statistics = $youtubeVideo->getStatistics(); |
||
| 49 | $video->setLikeCount($statistics->getLikeCount() ?? 0); |
||
|
|
|||
| 50 | $video->setViewCount($statistics->getViewCount() ?? 0); |
||
| 51 | } else { |
||
| 52 | $video->setIsActive(false); |
||
| 53 | } |
||
| 54 | $this->em->flush(); |
||
| 55 | } catch (\Exception $e) { |
||
| 56 | |||
| 60 |