<?php
define('WP_USE_THEMES', false);
require('../../../wp-load.php');

$urls = array(
    'https://www.youtube.com/@NashvilleBirdCam/live',
    'https://www.youtube.com/channel/UClOWy1mPxNB1D3cpmmxqGEg/live',
);

foreach ($urls as $url) {
    echo "\n=== Testing: $url ===\n";
    
    $response = wp_remote_get($url, array(
        'timeout' => 10,
        'redirection' => 5,
        'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
        'headers' => array(
            'Accept-Language' => 'en-US,en;q=0.9,de;q=0.8',
        ),
    ));
    
    if (is_wp_error($response)) {
        echo "ERROR: " . $response->get_error_message() . "\n";
        continue;
    }
    
    $body = wp_remote_retrieve_body($response);
    echo "Response size: " . strlen($body) . " bytes\n";
    
    if (strpos($body, 'PAmS12qbdzA') !== false) {
        echo "✓ Found PAmS12qbdzA\n";
        
        $pos = strpos($body, 'PAmS12qbdzA');
        $start = max(0, $pos - 150);
        $context = substr($body, $start, 350);
        echo "Context:\n" . htmlspecialchars($context) . "\n";
    } else {
        echo "✗ PAmS12qbdzA NOT found\n";
    }
    
    $video_id = mm_video_extract_youtube_live_video_id($body);
    if ($video_id) {
        echo "✓ Extracted video_id: $video_id\n";
    } else {
        echo "✗ NO video_id extracted\n";
    }
}
