type = $type;
$this->songs = $song_ids;
$this->web_path = conf('web_path');
if (conf('force_http_play')) {
$port = conf('http_port');
$this->web_path = preg_replace("/https/", "http",$this->web_path);
$this->web_path = preg_replace("/:\d+/",":$port",$this->web_path);
}
$this->sess = session_id();
$this->user_id = $_SESSION['userdata']['username'];
} //constructor
/*!
@function start
@discussion runs this and depending on the type passed it will
call the correct function
*/
function start() {
if (!is_array($this->songs)) {
debug_event('stream','Error: No Songs Passed on ' . $this->type . ' stream','2');
return false;
}
$methods = get_class_methods('Stream');
$create_function = "create_" . $this->type;
if (in_array($create_function,$methods)) {
$this->{$create_function}();
}
// Assume M3u incase they've pooched the type
else {
$this->create_m3u();
}
} // start
/**
* manual_url_add
* This manually adds a URL to the stream object for passing
* to whatever, this is an exception for when we don't actually
* have a object_id but instead a weird or special URL
*/
function manual_url_add($url) {
$this->urls[] = $url;
} // manual_url_add
/*!
@function create_simplem3u
@discussion this creates a simple m3u
without any of the extended information
*/
function create_simple_m3u() {
header("Cache-control: public");
header("Content-Disposition: filename=playlist.m3u");
header("Content-Type: audio/x-mpegurl;");
/* Foreach songs */
foreach ($this->songs as $song_id) {
$song = new Song($song_id);
if ($song->type == ".flac") { $song->type = ".ogg"; }
if($GLOBALS['user']->prefs['play_type'] == 'downsample') {
$ds = $GLOBALS['user']->prefs['sample_rate'];
}
echo "$this->web_path/play/index.php?song=$song_id&uid=$this->user_id&sid=$this->sess&ds=$ds&stupidwinamp=." . $song->type . "\n";
} // end foreach
/* Foreach the additional URLs */
foreach ($this->urls as $url) {
echo "$url\n";
}
} // simple_m3u
/*!
@function create_m3u
@discussion creates an m3u file
*/
function create_m3u() {
// Send the client an m3u playlist
header("Cache-control: public");
header("Content-Disposition: filename=playlist.m3u");
header("Content-Type: audio/x-mpegurl;");
echo "#EXTM3U\n";
foreach($this->songs as $song_id) {
$song = new Song($song_id);
$song->format_song();
if ($song->type == ".flac") { $song->type = ".ogg"; }
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
echo "#EXTINF:$song->time," . $song->f_artist_full . " - " . $song->title . "\n";
$sess = $_COOKIE[conf('sess_name')];
if($GLOBALS['user']->prefs['play_type'] == 'downsample') {
$ds = $GLOBALS['user']->prefs['sample_rate'];
}
echo $song->get_url() . "\n";
} // end foreach
/* Foreach URLS */
foreach ($this->urls as $url) {
echo "#EXTINF: URL-Add\n";
echo $url . "\n";
}
} // create_m3u
/*!
@function create_pls
@discussion creates a pls file
*/
function create_pls() {
/* Count entries */
$total_entries = count($this->songs) + count($this->urls);
// Send the client a pls playlist
header("Cache-control: public");
header("Content-Disposition: filename=playlist.pls");
header("Content-Type: audio/x-scpls;");
echo "[Playlist]\n";
echo "NumberOfEntries=$total_entries\n";
foreach ($this->songs as $song_id) {
$i++;
$song = new Song($song_id);
$song->format_song();
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
$song_url = $song->get_url();
echo "File" . $i . "=$song_url\n";
echo "Title" . $i . "=$song_name\n";
echo "Length" . $i . "=$song->time\n";
} // end foreach songs
/* Foreach Additional URLs */
foreach ($this->urls as $url) {
$i++;
echo "File" . $i ."=$url\n";
echo "Title". $i . "=AddedURL\n";
echo "Length" . $i . "=-1\n";
} // end foreach urls
echo "Version=2\n";
} // create_pls
/*!
@function create_asx
@discussion creates an ASZ playlist (Thx Samir Kuthiala)
*/
function create_asx() {
header("Cache-control: public");
header("Content-Disposition: filename=playlist.asx");
header("Content-Type: video/x-ms-asf;");
echo "