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,6 +1,71 @@
<?php
if (isset($_POST['rssUrl'])) {
$rssUrl = $_POST['rssUrl'];
// 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);
// Extract the channel title
preg_match('/<title>(.*?)<\/title>/i', $feedContent, $titleMatches);
$channelTitle = $titleMatches[1];
// 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.'
);
}
} else {
// Handle standard RSS and Atom feeds as before
$feed = simplexml_load_file($rssUrl);
if ($feed) {
@ -30,6 +95,7 @@ if (isset($_POST['rssUrl'])) {
'message' => 'Failed to parse RSS feed.'
);
}
}
} else {
$response = array(
'success' => false,