<?php
if (!function_exists('smurf_fetch_nowplaying_title')) {
function smurf_fetch_nowplaying_title(): string {
    require_once __DIR__ . '/stream_lib.php';

    $title = trim((string)smurf_get_nowplaying_title());
    if ($title !== '') {
        return $title;
    }

    $source = smurf_get_preferred_source();
    if (is_array($source)) {
        $fallback = trim((string)($source['server_name'] ?? $source['server_description'] ?? ''));
        if ($fallback !== '') {
            return $fallback;
        }
    }

    return 'Now Playing data unavailable.';
}
}
