예제 #1
0
파일: webmp3.php 프로젝트: sni/webmp3
function action_pic()
{
    global $config;
    $data = getData();
    $dst_w = 120;
    $dst_h = 120;
    if (isset($_REQUEST['token']) and isset($data["curTrack"])) {
        if ($data["curTrack"] == $_REQUEST['token']) {
            $dir = dirname($data["filename"]);
            $dir = str_replace($config["searchPath"], "", $dir);
            $_GET["pic"] = $dir;
        } elseif (isset($data['playlist'][$_REQUEST['token']])) {
            $dir = dirname($data['playlist'][$_REQUEST['token']]['filename']);
            $dir = str_replace($config["searchPath"], "", $dir);
            $_GET["pic"] = $dir;
        } else {
            $_GET["pic"] = "-1";
        }
    }
    if (!isset($_GET["pic"]) or empty($_GET["pic"])) {
        $_GET["pic"] = "-1";
    }
    $url = $config["searchPath"] . getPath($_GET["pic"]);
    $url = preg_replace("/\\/+/", "/", $url);
    $url = preg_replace("/\\/\$/", "", $url);
    doPrint("got pic request for: " . $url);
    # search a folder icon
    $url = getPictureForPath($url);
    if (file_exists($url)) {
        if (isset($_GET["full"]) and $_GET["full"] == "yes") {
            $tmp = explode(".", $url);
            $ext = "." . array_pop($tmp);
            $ct = "text/plain";
            if ($ext == ".png") {
                $ct = "image/png";
            }
            if ($ext == "jpeg") {
                $ct = "image/jpg";
            }
            if ($ext == ".jpg") {
                $ct = "image/jpg";
            }
            if ($ext == ".gif") {
                $ct = "image/gif";
            }
            header("Content-type: " . $ct);
            readfile($url);
            exit;
        }
        if (isset($data["cachedPic"]) and $url == $data["cachedPic"] and is_file("./var/cache.jpg")) {
            # is there a cached one?
            doPrint("got pic from cache");
            header("Content-type: image/jpeg");
            readfile("./var/cache.jpg");
            exit;
        }
        switch (exif_imagetype($url)) {
            case 1:
                $img = imagecreatefromgif($url);
                break;
            case 2:
                $img = imagecreatefromjpeg($url);
                break;
            case 3:
                $img = imagecreatefrompng($url);
                break;
            case 4:
                $img = imagecreatefromwbmp($url);
                break;
        }
        list($w, $h) = getimagesize($url);
        $dst = imagecreatetruecolor($dst_w, $dst_h);
        imagecopyresampled($dst, $img, 0, 0, 0, 0, $dst_w, $dst_h, $w, $h);
        header("Content-type: image/jpeg");
        imagejpeg($dst);
        #doPrint("-".$data["playingPic"]."-");
        #doPrint("-".$url."-");
        if (isset($data["playingPic"]) and $data["playingPic"] == $url) {
            doPrint("saved pic to cache");
            imagejpeg($dst, "./var/cache.jpg");
            $data["cachedPic"] = $url;
            storeData($data);
        }
    } else {
        print $url . " is not a file";
    }
}
예제 #2
0
파일: play.php 프로젝트: sni/webmp3
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();
        }
    }
}
예제 #3
0
파일: common.php 프로젝트: sni/webmp3
function getPictureForPath($path)
{
    global $config;
    if (file_exists($path . "/folder.gif")) {
        $return = $path . "/folder.gif";
    } elseif (file_exists($path . "/folder.jpg")) {
        $return = $path . "/folder.jpg";
    } elseif (file_exists($path . "/folder.png")) {
        $return = $path . "/folder.png";
    } elseif (is_dir($path) and $handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            $tmp = explode(".", $file);
            $ext = "." . array_pop($tmp);
            if ($ext == ".png" or $ext == ".jpg" or $ext == ".bmp" or $ext == ".gif") {
                $return = $path . "/" . $file;
            }
        }
    }
    if (empty($return)) {
        $path = str_replace($config['searchPath'], "", $path);
        $lowerPath = getPath($path . "/..");
        if (getPath($path) != $lowerPath) {
            $return = getPictureForPath($config['searchPath'] . $lowerPath);
        }
    }
    if (empty($return)) {
        $return = "images/white.png";
    }
    $return = preg_replace("/\\/+/", "/", $return);
    return $return;
}