示例#1
0
     debuglog("Adding Item " . $cmd[1], "POSTCOMMAND");
     $cmds = array_merge($cmds, getItemsToAdd($cmd[1], null));
     break;
 case "addartist":
     require_once "backends/sql/backend.php";
     debuglog("Getting tracks for Artist " . $cmd[1], "MPD");
     doCollection('find "artist" "' . format_for_mpd($cmd[1]) . '"', array("spotify"));
     $cmds = array_merge($cmds, $collection->getAllTracks("add"));
     break;
 case "loadstreamplaylist":
     require_once "utils/getInternetPlaylist.php";
     $cmds = array_merge($cmds, load_internet_playlist($cmd[1], $cmd[2], $cmd[3], $cmd[4]));
     break;
 case "loaduserstream":
     require_once "utils/getInternetPlaylist.php";
     $cmds = array_merge($cmds, get_tracks_from_stream_playlist($cmd[1]));
     break;
 case "rename":
     $oldimage = md5('Playlist ' . $cmd[1]);
     $newimage = md5('Playlist ' . $cmd[2]);
     if (file_exists('albumart/small/' . $oldimage . '.jpg')) {
         debuglog("Renaming playlist image for " . $cmd[1] . " to " . $cmd[2], "MPD");
         system('mv "albumart/small/' . $oldimage . '.jpg" "albumart/small/' . $newimage . '.jpg"');
         system('mv "albumart/asdownloaded/' . $oldimage . '.jpg" "albumart/asdownloaded/' . $newimage . '.jpg"');
     }
     $playlist_file = format_for_disc(rawurldecode($cmd[1]));
     $new_file = format_for_disc(rawurldecode($cmd[2]));
     system('mv "prefs/' . $playlist_file . '" "prefs/' . $new_file . '"');
     $cmds[] = join_command_string($cmd);
     break;
 case "playlistadd":
示例#2
0
function load_internet_playlist($url, $image, $station, $usersupplied)
{
    $station = $station == 'null' ? 'Unknown Internet Stream' : $station;
    $image = $image == 'null' ? 'newimages/broadcast.svg' : $image;
    $usersupplied = $usersupplied == 'null' ? false : true;
    $creator = "";
    debuglog("Getting Internet Stream:", "RADIO_PLAYLIST");
    debuglog("  url : " . $url, "RADIO_PLAYLIST");
    debuglog("  station : " . $station, "RADIO_PLAYLIST");
    debuglog("  image : " . $image, "RADIO_PLAYLIST");
    debuglog("  user : "******"RADIO_PLAYLIST");
    if ($url) {
        $path = $url;
        $type = null;
        $content = url_get_contents($url, $_SERVER['HTTP_USER_AGENT'], false, true, true);
        debuglog("Playlist Is " . $content['status'] . " " . $content['contents'], "RADIO_PLAYLIST");
        $content_type = $content['info']['content_type'];
        // To cope with charsets in the header...
        // case "audio/x-scpls;charset=UTF-8";
        $content_type = preg_replace('/;.*/', '', $content_type);
        switch ($content_type) {
            case "video/x-ms-asf":
                $type = asfOrasx($content['contents']);
                break;
            case "audio/x-scpls":
                $type = "pls";
                break;
            case "audio/x-mpegurl":
                $type = "m3u";
                break;
            case "application/xspf+xml":
                $type = "xspf";
                break;
            case "text/html":
                debuglog("HTML page returned!", "RADIO_PLAYLIST");
                header('HTTP/1.0 404 Not Found');
                exit(0);
        }
        debuglog("Playlist Type From Content Type is " . $type, "RADIO_PLAYLIST");
        if ($type == "" || $type == null) {
            $type = pathinfo($path, PATHINFO_EXTENSION);
            $qpos = strpos($type, "?");
            if ($qpos != false) {
                $type = substr($type, 0, $qpos);
            }
            debuglog("Playlist Type From URL is " . $type, "RADIO_PLAYLIST");
        }
        $playlist = null;
        if ($content['status'] == "200" && $content['contents'] != "") {
            switch ($type) {
                case "pls":
                case "PLS":
                    $playlist = new plsFile($content['contents'], $url, $station, $creator, $image);
                    break;
                case "asx":
                case "ASX":
                    $playlist = new asxFile($content['contents'], $url, $station, $creator, $image);
                    break;
                case "asf":
                case "ASF":
                    $playlist = new asfFile($content['contents'], $url, $station, $creator, $image);
                    break;
                case "xspf":
                case "XSPF":
                    $playlist = new xspfFile($content['contents'], $url, $station, $creator, $image);
                    break;
                case "m3u":
                case "M3U":
                    $playlist = new m3uFile($content['contents'], $url, $station, $creator, $image);
                    break;
                default:
                    $playlist = new possibleStreamUrl($url, $station, $creator, $image);
                    break;
            }
        } else {
            if ($content['status'] == "404") {
                $playlist = null;
            } else {
                $playlist = new possibleStreamUrl($url, $station, $creator, $image);
            }
        }
        if ($playlist) {
            list($tl, $st) = $playlist->getTracks();
            header('Content-Type: text/xml; charset=utf-8');
            $output = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . "<playlist>\n" . "<playlisturl>" . htmlspecialchars($url) . "</playlisturl>\n" . '<trackList>' . "\n";
            $output = $output . $tl;
            $output = $output . "</trackList>\n</playlist>\n";
            $fp = null;
            $fname = $usersupplied ? 'prefs/USERSTREAM_' . md5($url) . '.xspf' : 'prefs/STREAM_' . md5($url) . '.xspf';
            $fp = fopen($fname, 'w');
            if ($fp) {
                fwrite($fp, $output);
            }
            fclose($fp);
            return get_tracks_from_stream_playlist($fname);
        } else {
            debuglog("Could not determine playlist type", "RADIO_PLAYLIST");
        }
    }
}