Trying to get the latest video of an Odysee.com channel

I’ve written this as i’d like to get the latest channel of The Duran from Odysee

However when I run it I don’t get the latest video

<?php
// Include the Simple HTML DOM Parser library
include('simple_html_dom.php');

function fetchLatestOdyseeVideo($channelName) {
    // Create the URL of the channel page
    $channelUrl = "https://odysee.com/$channelName";

    // Initialize cURL session
    $ch = curl_init($channelUrl);

    // Set cURL options
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL certificate verification (use only for development)
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Timeout in seconds

    // Execute the cURL request
    $html = curl_exec($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        return 'cURL error: ' . curl_error($ch);
    }

    // Parse the HTML using Simple HTML DOM Parser
    $dom = new simple_html_dom();
    $dom->load($html);

    // Find the latest video title and URL
    $latestVideo = $dom->find('div.video', 0);
    if ($latestVideo) {
        $videoTitle = $latestVideo->find('a.title', 0)->plaintext;
        $videoUrl = 'https://odysee.com' . $latestVideo->find('a.title', 0)->href;
        
        return [
            'title' => $videoTitle,
            'url' => $videoUrl,
        ];
    } else {
        return 'No videos found for the channel.';
    }

    // Close cURL session
    curl_close($ch);
}

// Example usage:
$channelName = '@theduran';
$latestVideoInfo = fetchLatestOdyseeVideo($channelName);

if (is_array($latestVideoInfo)) {
    echo "Latest video title: " . $latestVideoInfo['title'] . "\n";
    echo "Latest video URL: " . $latestVideoInfo['url'] . "\n";
} else {
    echo $latestVideoInfo;
}
?>

Sponsor our Newsletter | Privacy Policy | Terms of Service