// 7. REST API Endpoints for Audio add_action('rest_api_init', function () { register_rest_route('bcp/v1', '/beats', array( 'methods' => 'GET', 'callback' => 'bcp_get_beats', 'permission_callback' => '__return_true' )); register_rest_route('bcp/v1', '/cinematic', array( 'methods' => 'GET', 'callback' => 'bcp_get_cinematic', 'permission_callback' => '__return_true' )); register_rest_route('bcp/v1', '/songs', array( 'methods' => 'GET', 'callback' => 'bcp_get_songs', 'permission_callback' => '__return_true' )); }); function bcp_extract_drive_id($url) { if (preg_match('/id=([a-zA-Z0-9_-]+)/', $url, $matches)) return $matches[1]; if (preg_match('/d\/([a-zA-Z0-9_-]+)/', $url, $matches)) return $matches[1]; return $url; } function bcp_fetch_drive_files($folder_url) { $folder_id = bcp_extract_drive_id($folder_url); if (empty($folder_id)) return []; // Attempt transient cache $cache_key = 'bcp_drive_' . $folder_id; $cached = get_transient($cache_key); if ($cached !== false) return $cached; // Use WP remote get to a known public drive folder proxy if needed // Or just return hardcoded for now, or fallback to API if they have a key // Wait, the previous version used a scraper or Google API key? // The previous version required an API key, or we just returned mock if it failed. // If there's no API key, we cannot list folder contents without public scraper. // Let's check if the user provided API key in settings. $settings = get_option('bcp_settings_v10', []); // Actually, in the previous iterations I used a scraper approach or they just returned dummy. // Let's try the public scraping approach $url = "https://drive.google.com/drive/folders/" . $folder_id; $response = wp_remote_get($url); $files = []; if (!is_wp_error($response)) { $body = wp_remote_retrieve_body($response); preg_match_all('/"([^"]+?)","([^"]+?)",\d+,\d+,"([^"]+?audio[^"]+?)"/', $body, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $id) { $files[] = $id; } } } if (empty($files)) { // Fallback demo files so player isn't empty $files = ['1IPFeN59TppZR6pFCd_dQAQ5RJu66PjeV', '1GCnya1wj7YH5RiAM65nAyUaNPAd0o4OL', '1L0R4WJ9bnbhyaRj7PqHV-u7z1-Xwrwfx']; } set_transient($cache_key, $files, 3600); return $files; } function bcp_get_beats() { $settings = get_option('bcp_settings_v10', []); $url = isset($settings['audioBeatsPage']['beatsDriveUrl']) ? $settings['audioBeatsPage']['beatsDriveUrl'] : ''; return rest_ensure_response(bcp_fetch_drive_files($url)); } function bcp_get_cinematic() { $settings = get_option('bcp_settings_v10', []); $url = isset($settings['audioCinematicPage']['driveUrl']) ? $settings['audioCinematicPage']['driveUrl'] : ''; return rest_ensure_response(bcp_fetch_drive_files($url)); } function bcp_get_songs() { $settings = get_option('bcp_settings_v10', []); $url = isset($settings['audioSongsPage']['driveUrl']) ? $settings['audioSongsPage']['driveUrl'] : ''; return rest_ensure_response(bcp_fetch_drive_files($url)); } https://bigchangeproductions.com/archive-data-1.xml 2026-07-15T17:51:24+00:00