channel; $title = (string) $channel->title; // Find episode by url and add data for it /** @var \SimpleXMLElement $item */ foreach ($channel->item as $item) { $url = (string) $item->enclosure['url']; $type = (string) $item->enclosure['type']; $size = (int) $item->enclosure['length']; $guid = (string) $item->guid; $iTunesItemChildren = $item->children('itunes', true); $iTunesChannelChildren = $channel->children('itunes', true); // Get episode action $action = $this->episodeActionRepository->findByGuid($guid, $this->userService->getUserUID()); if ($action) { $url = $action->getEpisode(); } else { $action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID()); } // Get episode name $name = (string) $item->title; // Get episode link $link = $this->stringOrNull($item->link); // Get episode image $image = $this->stringOrNull($item->image->url); if (!$image && $iTunesItemChildren) { $imageAttributes = $iTunesItemChildren->image->attributes(); $image = $this->stringOrNull($imageAttributes ? (string) $imageAttributes->href : ''); } if (!$image) { $image = $this->stringOrNull($channel->image->url); } if (!$image && $iTunesChannelChildren) { $imageAttributes = $iTunesChannelChildren->image->attributes(); $image = $this->stringOrNull($imageAttributes ? (string) $imageAttributes->href : ''); } if (!$image) { preg_match('/stringOrNull($matches[1]); } // Get episode description $itemContent = $item->children('content', true); if ($itemContent) { $description = $this->stringOrNull($itemContent->encoded); } else { $description = $this->stringOrNull($item->description); } if (!$description && $iTunesItemChildren) { $description = $this->stringOrNull($iTunesItemChildren->summary); } // Remove tags $description = strip_tags(str_replace(['
', '
', '
'], "\n", $description ?? '')); // Get episode duration if ($iTunesItemChildren) { $rawDuration = $this->stringOrNull($iTunesItemChildren->duration); } else { $rawDuration = $this->stringOrNull($item->duration); } $splitDuration = array_reverse(explode(':', $rawDuration ?? '')); $duration = (int) $splitDuration[0]; $duration += !empty($splitDuration[1]) ? (int) $splitDuration[1] * 60 : 0; $duration += !empty($splitDuration[2]) ? (int) $splitDuration[2] * 60 : 0; // Get episode pubDate $rawPubDate = $this->stringOrNull($item->pubDate); $pubDate = $rawPubDate ? new \DateTime($rawPubDate) : null; $episodes[] = new EpisodeActionExtraData( $title, $url, $name, $link, $image, $description, $fetchedAtUnix ?? (new \DateTime())->getTimestamp(), $guid, $type, $size, $pubDate, $duration, $action ); } return $episodes; } /** * @param null|\SimpleXMLElement|string $value */ private function stringOrNull($value): ?string { if ($value) { return (string) $value; } return null; } }