Beispiel #1
0
function action_default()
{
    global $config;
    $data = getData();
    if (isset($data["ppid"])) {
        $data = killChild($data);
    }
    if (isset($data["curTrack"]) and isset($data["playlist"][$data["curTrack"]])) {
        $track = $data["playlist"][$data["curTrack"]];
    } else {
        $tmp = $data["playlist"];
        $track = array_shift($tmp);
        $data["curTrack"] = $track["token"];
    }
    doPrint("playing: " . $track["filename"]);
    # clean up playlist
    if ($data['partymode'] == 1) {
        # clean everything up to 3 songs after the current one
        $x = 0;
        $num = 0;
        foreach ($data['playlist'] as $token => $tr) {
            if ($tr['token'] == $track["token"]) {
                $num = $x;
                continue;
            }
            $x++;
        }
        $num = $num - 3;
        $num = max(0, $num);
        for ($x = 0; $x < $num; $x++) {
            array_shift($data["playlist"]);
        }
    } elseif ($data['partymode'] == 2) {
        # clean everything up to the first song of the cur album
        $newPlaylist = array();
        $found = 0;
        foreach ($data['playlist'] as $token => $tr) {
            if ($tr['token'] == $track["token"] or $tr['album'] == $track['album']) {
                $found = 1;
            }
            if ($found == 1) {
                $newPlaylist[$token] = $tr;
            }
        }
        $data['playlist'] = $newPlaylist;
    }
    $data["start"] = time();
    $data["length"] = $track["lengths"];
    $data["title"] = $track["title"];
    $data["artist"] = $track["artist"];
    $data["album"] = $track["album"];
    $data["track"] = $track["tracknum"];
    $data["token"] = $track["token"];
    $data["filename"] = $track["filename"];
    if (!isset($track["bitrate"])) {
        $track["bitrate"] = "";
    }
    $data["bitrate"] = $track["bitrate"];
    $data["play"] = 1;
    $data["gmtimestart"] = gmdate("U");
    $data["playingPic"] = getPictureForPath(dirname($track["filename"]));
    if (isset($config["notifyCommand"])) {
        $tmp = $config["notifyCommand"];
        $tmpTrack = $track["tracknum"];
        $tmpArtist = $track["artist"];
        $tmpTitle = $track["title"];
        $tmpArtist = str_replace('\'', '', $tmpArtist);
        $tmpArtist = str_replace('\\"', '', $tmpArtist);
        $tmpArtist = str_replace(';', '', $tmpArtist);
        $tmpTitle = str_replace('\'', '', $tmpTitle);
        $tmpTitle = str_replace('\\"', '', $tmpTitle);
        $tmpTitle = str_replace(';', '', $tmpTitle);
        $tmpTrack = str_replace('\'', '', $tmpTrack);
        $tmpTrack = str_replace('\\"', '', $tmpTrack);
        $tmpTrack = str_replace(';', '', $tmpTrack);
        $tmp = str_replace("%#", $tmpTrack, $tmp);
        $tmp = str_replace("%T", $tmpTitle, $tmp);
        $tmp = str_replace("%A", $tmpArtist, $tmp);
        doPrint("notify: " . $tmp);
        $output = "";
        $rc = 0;
        exec($tmp, $output, $rc);
        if ($rc != 0) {
            doPrint("notify failed: " . join("\n", $output));
        }
    }
    $data["ppid"] = getmypid();
    # most played
    addFileToHitlist($track["filename"]);
    if (strpos($track["filename"], "http://") === 0) {
        doPrint("playing stream");
        $options = $config["playStrOpt"];
        $playBin = $config["streamBin"];
        if (!isset($config["streamUrlPre"])) {
            $config["streamUrlPre"] = "";
        }
        $track["filename"] = $config["streamUrlPre"] . $track["filename"];
        $data["playingStream"] = 1;
    } else {
        doPrint("playing normal file");
        $tmp = explode(".", $track["filename"]);
        $ext = "." . array_pop($tmp);
        if (isset($config["ext"][$ext])) {
            $playBin = $config["ext"][$ext]["binary"];
            $options = $config["ext"][$ext]["option"];
        } else {
            doPrint("Extension {$ext} not supported");
        }
        $data["playingStream"] = 0;
    }
    $options[] = $track["filename"];
    $data["aktBin"] = $playBin;
    storeData($data);
    #$options = array_map("myescapeshellarg", $options);
    setlocale(LC_CTYPE, "en_US.UTF-8");
    $options = array_map("escapeshellarg", $options);
    $data = brokerPlugin("pre_playing_song", $data);
    doPrint("executing: " . $playBin . " " . join(" ", $options));
    system($playBin . " " . join(" ", $options) . ' >> ' . $config["logfile"] . ' 2>&1');
    doPrint("finished playing");
    $data = getData();
    $data = brokerPlugin("post_playing_song", $data);
    unset($data["ppid"]);
    unset($data["start"]);
    unset($data["length"]);
    unset($data["title"]);
    unset($data["track"]);
    unset($data["artist"]);
    unset($data["album"]);
    unset($data["aktBin"]);
    unset($data["playingPic"]);
    $lastToken = $track["token"];
    $track = "";
    storeData($data);
    if ($data["play"]) {
        $data["play"] = 0;
        $track = getNextTrack($data["playlist"], $lastToken);
        if ($track) {
            $data["curTrack"] = $track;
            storeData($data);
            action_default();
        }
    }
}
Beispiel #2
0
 function sendSongToLastFM($data, $nowplaying = 0)
 {
     global $config;
     if (!isset($data["title"]) or empty($data["title"]) or !isset($data["artist"]) or empty($data["artist"]) or !isset($data["album"]) or empty($data["album"])) {
         return 1;
     }
     $length = $data["length"];
     $title = $data["title"];
     $artist = $data["artist"];
     $album = $data["album"];
     $track = $data["track"];
     // ???
     $time = $data["gmtimestart"];
     $played_sec = gmdate("U") - $time;
     if ($nowplaying == 0) {
         if ($played_sec < 30) {
             doPrint("lastfm: song must have been played for at least 30 seconds, this one has: " . $played_sec);
             return 1;
         }
     }
     if ($length < 30) {
         doPrint("lastfm: songs have to be at least 30 seconds long, this one has: " . $length);
         return 1;
     }
     if ($nowplaying == 0) {
         doPrint("lastfm: sending last played song");
         $cmd = $this->command . ' --album ' . escapeshellarg($album) . ' --artist ' . escapeshellarg($artist) . ' --title ' . escapeshellarg($title) . ' --length ' . escapeshellarg($length) . ' 2>&1';
         //.' --time '    .escapeshellarg($time)
         exec($cmd, $output = array(), $return);
         if ($return != 0) {
             doPrint("lastfm: {$cmd}");
             doPrint($output);
             doPrint($return);
             return 1;
         }
     } else {
         doPrint("lastfm: sending current playing song not implemented yet");
     }
 }
Beispiel #3
0
function action_getHitlist()
{
    global $config;
    #doPrint($_REQUEST);
    $start = 0;
    $limit = 20;
    if (isset($_REQUEST['start']) and is_numeric($_REQUEST['start'])) {
        $start = $_REQUEST['start'];
    }
    if (isset($_REQUEST['limit']) and is_numeric($_REQUEST['limit'])) {
        $limit = $_REQUEST['limit'];
    }
    doPrint("got json hitlist request (" . $start . "/" . $limit . ")");
    $songs = file($config["hitlist"]) or die("cannot open hitlist file");
    $hitlist = array();
    foreach ($songs as $song) {
        list($num, $track) = explode(",", $song);
        $hitlist[$num][] = $track;
    }
    krsort($hitlist);
    $newHitlist = array();
    $x = 1;
    foreach ($hitlist as $num => $tracks) {
        foreach ($tracks as $track) {
            $newHitlist[] = array("nr" => $x, "file" => $track, "count" => $num);
            $x++;
        }
    }
    $count = count($newHitlist);
    $newHitlist = array_slice($newHitlist, $start, $limit);
    if (count($newHitlist) > 0) {
        $data = json_encode($newHitlist);
        echo '({"total":"' . $count . '","results":' . $data . '})';
    } else {
        echo '({"total":"0", "results":""})';
    }
}
Beispiel #4
0
function getAccess($path)
{
    global $config;
    # check if access control is enabled
    if ($config["accControl"] == 0) {
        return 1;
    }
    $allowed = 1;
    if (isset($config["allowedDirs"])) {
        foreach ($config["allowedDirs"] as $dir => $ips) {
            if (strpos($path, $dir) !== false) {
                $allowed = 0;
                doPrint("path ('" . $path . "') is protected");
                if (!isset($_SERVER["REMOTE_ADDR"])) {
                    doPrint("remote ip is not set");
                } elseif (!in_array($_SERVER["REMOTE_ADDR"], $ips)) {
                    doPrint("ip: " . $_SERVER["REMOTE_ADDR"] . " is not allowed");
                } else {
                    doPrint("ip: " . $_SERVER["REMOTE_ADDR"] . " is allowed");
                    $allowed = 1;
                }
            }
        }
    }
    return $allowed;
}
<?php

include "myOtherScript.php";
print "This was printed from the includeScript.php";
print "<BR>";
doPrint();
Beispiel #6
0
 function urlSend($url, $post = 0, $retries = 0, $session = "")
 {
     global $config;
     $new_url = $url;
     if ($session != "") {
         $new_url = $url . "&s=" . $session;
     }
     doPrint("lastfm: url " . $new_url);
     $ch = curl_init($new_url);
     curl_setopt($ch, "CURLOPT_USERAGENT", "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
     curl_setopt($ch, "CURLOPT_TIMEOUT", "10");
     if (isset($config["lastfm_proxy"]) and !empty($config["lastfm_proxy"])) {
         curl_setopt($ch, CURLOPT_PROXY, $config["lastfm_proxy"]);
     }
     if ($post == 1) {
         $postOpts = preg_replace("/.*?\\?/", "", $url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postOpts);
     }
     ob_start();
     if (!curl_exec($ch)) {
         $err = curl_error($ch);
         doPrint("lastfm: Curl Error", "ERROR");
         doPrint("lastfm: " . curl_error($ch), "ERROR");
         return $err;
     }
     $cont = ob_get_contents();
     ob_end_clean();
     curl_close($ch);
     $con = explode("\n", $cont);
     if ($con[0] == "BADSESSION") {
         doPrint("lastfm: session expired, retry(" . $retries . ")");
         $data = getData();
         unset($data["lastfm_sessionid"]);
         unset($data["lastfm_nowplaying"]);
         unset($data["lastfm_submission"]);
         $data = $this->lastFMHandshake($data);
         if (isset($data['lastfm_submission']) and isset($data['lastfm_sessionid']) and $retries <= 0) {
             $retries++;
             doPrint("lastfm: trying once more");
             sleep(2);
             $this->urlSend($url, $post, $retries, $data["lastfm_sessionid"]);
         }
     }
     if (empty($cont)) {
         $cont = "UNKNOWN";
     }
     #doPrint("lastfm: Content:");
     #doPrint($cont);
     return $cont;
 }