1 URL⇒ 2023-08-12 09:45:12

Тема: Вещание, вывод треков на сайт

Добрый всем! Подскажите как из списка сделать ссылки на поиск в соц сетях?

<?php
 
//max recent tracks to keep in the recently played tracks history
$max_recent = 50;
 
//secret key to access the script
$key = '4567';
 
//check access
if ($_REQUEST['key'] !== $key) {
    ReturnError(400, 'Invalid key');
}
 
//retrieve title info
$title = htmlspecialchars($_REQUEST['casttitle']);
 
//save current track title and update history
$file = 'nowplaying_title.txt';
$recent = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$recent = array_slice($recent, 0, $max_recent);
 
$r = fopen($file, 'wb');
if ($r !== false) {
    //current track
    fwrite($r, $title . "\n");
    //recent tracks
    foreach ($recent as $s) {
        fwrite($r, $s . "\n");
    }
    fclose($r);
} else {
    ReturnError(500, 'Failed to save track title');
}
 
//album cover
$artwork = isset($_REQUEST['artwork']) && ($_REQUEST['artwork'] !== '') ? $_REQUEST['artwork'] : false;
if ($artwork !== false) {
    $artwork = base64_decode($artwork);
    $r = fopen('nowplaying_artwork.png', 'wb');
    if ($r !== false) {
        fwrite($r, $artwork);
        fclose($r);
    } else {
        ReturnError(500, 'Failed to save track artwork');
    }
}
 
function ReturnError($code, $text) {
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    header($protocol . ' ' . $code . ' ' . $text);
    exit();
}

Вывод txt файла вот этим скриптом!

<div id="np_recent_tracks"></div>
 
<script>
    function updateTitleDisplay() {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if ((xmlhttp.readyState === 4) && (xmlhttp.status === 200)) {
                var s = xmlhttp.responseText;
                s = s.split('\n');
                //current track
                document.querySelector('#np_current_track').innerHTML = s[0];
                //played tracks history
                var t = '', i;
                for (i = 1; i < s.length; i++) {
                    t += s[i];
                    if (i !== s.length - 1)
                        t += '<br>';
                }
                document.querySelector('#np_recent_tracks').innerHTML = t;
            }
        };
        xmlhttp.open("GET", "nowplaying_title.txt?"  + new Date().getTime(), true);
        xmlhttp.send();
    }
 
    //update every 5 seconds
    document.addEventListener('DOMContentLoaded', function () {
        setInterval(updateTitleDisplay, 5 * 1000);
        updateTitleDisplay();
    });
</script>

nowplaying.zip

tracktitle.zip

Поделиться

1