youtube rss support added

This commit is contained in:
Neovoid Pineapple 2023-07-01 08:22:14 +00:00
parent 2f21f6071e
commit 4d685b3be9

View file

@ -1,34 +1,100 @@
<?php
if (isset($_POST['rssUrl'])) {
$rssUrl = $_POST['rssUrl'];
$feed = simplexml_load_file($rssUrl);
if ($feed) {
$feedTitle = (string) $feed->channel->title;
$feeds = array();
// Check if the provided URL is a YouTube RSS feed
if (strpos($rssUrl, 'youtube.com/feeds/videos.xml') !== false) {
// Load the YouTube RSS feed
$feedContent = file_get_contents($rssUrl);
foreach ($feed->channel->item as $item) {
$title = (string) $item->title;
$date = (string) $item->pubDate;
$content = (string) $item->description;
// Extract the channel title
preg_match('/<title>(.*?)<\/title>/i', $feedContent, $titleMatches);
$channelTitle = $titleMatches[1];
$feeds[] = array(
'title' => $title,
'date' => $date,
'content' => $content
// Extract the videos
preg_match_all('/<entry>(.*?)<\/entry>/is', $feedContent, $videoMatches);
$videoData = $videoMatches[1];
if (!empty($videoData)) {
$feeds = array();
foreach ($videoData as $video) {
// Extract the video title
preg_match('/<title[^>]*>(.*?)<\/title>/i', $video, $titleMatches);
$title = $titleMatches[1];
// Extract the published date
preg_match('/<published>(.*?)<\/published>/i', $video, $dateMatches);
$date = $dateMatches[1];
// Extract the video ID
preg_match('/<yt:videoId>(.*?)<\/yt:videoId>/i', $video, $videoIdMatches);
$videoId = $videoIdMatches[1];
// Build the video URL
$videoUrl = 'https://www.youtube.com/watch?v=' . $videoId;
// Extract the video descriptions
preg_match_all('/<media:description>(.*?)<\/media:description>/is', $video, $descriptionMatches);
$descriptions = $descriptionMatches[1];
// Generate the video content
$content = '<div><a href="' . $videoUrl . '">Watch on YouTube</a></div>';
foreach ($descriptions as $description) {
$content .= '<div>' . $description . '</div>';
}
$feeds[] = array(
'title' => $title,
'date' => $date,
'content' => $content
);
}
$feedTitle = 'YouTube Channel: ' . $channelTitle;
$response = array(
'success' => true,
'feedTitle' => $feedTitle,
'feeds' => $feeds
);
} else {
$response = array(
'success' => false,
'message' => 'No videos found for the provided YouTube channel.'
);
}
$response = array(
'success' => true,
'feedTitle' => $feedTitle,
'feeds' => $feeds
);
} else {
$response = array(
'success' => false,
'message' => 'Failed to parse RSS feed.'
);
// Handle standard RSS and Atom feeds as before
$feed = simplexml_load_file($rssUrl);
if ($feed) {
$feedTitle = (string) $feed->channel->title;
$feeds = array();
foreach ($feed->channel->item as $item) {
$title = (string) $item->title;
$date = (string) $item->pubDate;
$content = (string) $item->description;
$feeds[] = array(
'title' => $title,
'date' => $date,
'content' => $content
);
}
$response = array(
'success' => true,
'feedTitle' => $feedTitle,
'feeds' => $feeds
);
} else {
$response = array(
'success' => false,
'message' => 'Failed to parse RSS feed.'
);
}
}
} else {
$response = array(