Example #1
0
        }
        // check for duplicate channel names
        if (isset($a[$normalizedChannelKey])) {
            if ($a[$normalizedChannelKey]['path'] == $entry->getPath()) {
                echo "Skipping duplicate entry for '{$normalizedChannelName}'." . PHP_EOL;
                continue;
            }
            // distinguish them by URL hash
            $suffix = ' | ' . sha1($entry->getPath());
        }
        $a[$normalizedChannelKey . $suffix] = ['name' => $normalizedChannelName . $suffix, 'path' => $entry->getPath()];
    }
}
ksort($a);
print_r($a);
writePlaylist($a);
function normalizeChannelKey($channelName)
{
    $channelName = preg_replace('/[^\\w]/', '', $channelName);
    return strtolower($channelName);
}
function normalizeChannelName($channelName)
{
    $channelName = trim($channelName, ':');
    $channelName = trim($channelName);
    if (strlen($channelName) == 0) {
        $channelName = 'Unknown';
    }
    return $channelName;
}
function validUrl($url)
Example #2
0
function watchdog()
{
    $app = Slim\Slim::getInstance();
    $app->contentType('application/json');
    $log = $app->getLog();
    $watchdog = getWatchdog();
    $newWatchdog = $watchdog;
    $body = array();
    switch ($watchdog) {
        case 'PLAY':
            $playlist = readPlaylist();
            exec('pgrep omxplayer.bin', $pids);
            if (sizeof($playlist) > 0) {
                if (empty($pids)) {
                    // play next from playlist
                    $file = trim($playlist[0]);
                    $log->info("-> watchdog stopped, play " . $file);
                    $playlist = array_slice($playlist, 1);
                    if (writePlaylist($playlist) !== false) {
                        $out = play($file);
                        $body['message'] = $out;
                    }
                } else {
                    $log->info("-> watchdog playing, wait for end");
                }
            } else {
                if (empty($pids)) {
                    // out of playlist and player stopped
                    $newWatchdog = 'STOPPED';
                    $log->info("-> watchdog stopped, no more tracks queued");
                } else {
                    $log->info("-> watchdog still playing, no more tracks queued");
                }
            }
            break;
        case 'STOP':
            $newWatchdog = 'STOPPED';
            break;
        default:
            break;
    }
    if ($watchdog != $newWatchdog) {
        setWatchdog($newWatchdog);
    }
    $body['watchdog'] = $newWatchdog;
    echo json_encode($body);
    $response = $app->response();
    $response["Cache-Control"] = "max-age=5";
    $log->info("-> watchdog, status " . $newWatchdog);
    /*
    //polling takes too much CPU time
    if ($newWatchdog == 'PLAY') {
    	usleep(1000000);
    	wakeWatchdog('http://localhost/omxplayer-ui/watchdog');
    }
    */
}