diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-02-28 18:13:48 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-02-28 18:13:48 +0000 |
commit | dbdd96ed1b3b00a850be001f3dbeea3273739a98 (patch) | |
tree | ccd23afffb6a4c2dc185bd6ffc39e13435fc1179 /lib/class/stream.class.php | |
parent | 3a3e0c6a9f72d5031a4025dedcf2360c497c4953 (diff) | |
download | ampache-dbdd96ed1b3b00a850be001f3dbeea3273739a98.tar.gz ampache-dbdd96ed1b3b00a850be001f3dbeea3273739a98.tar.bz2 ampache-dbdd96ed1b3b00a850be001f3dbeea3273739a98.zip |
unify how the stream is constructed and played, this is a major change might be some regressions
Diffstat (limited to 'lib/class/stream.class.php')
-rw-r--r-- | lib/class/stream.class.php | 219 |
1 files changed, 132 insertions, 87 deletions
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 9de66510..ec8308e5 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -31,7 +31,7 @@ class Stream { /* Variables from DB */ public $type; public $web_path; - public $songs = array(); + public $media = array(); public $urls = array(); public $sess; public $user_id; @@ -46,10 +46,10 @@ class Stream { * Constructor for the stream class takes a type and an array * of song ids */ - public function __construct($type='m3u', $song_ids=0) { + public function __construct($type='m3u', $media_ids=0) { $this->type = $type; - $this->songs = $song_ids; + $this->media = $media_ids; $this->web_path = Config::get('web_path'); $this->user_id = $GLOBALS['user']->id; @@ -66,7 +66,7 @@ class Stream { */ public function start() { - if (!count($this->songs) AND !count($this->urls)) { + if (!count($this->media) AND !count($this->urls)) { debug_event('stream','Error: No Songs Passed on ' . $this->type . ' stream','2'); return false; } @@ -99,7 +99,12 @@ class Stream { */ public function manual_url_add($url) { - $this->urls[] = $url; + if (is_array($url)) { + $this->urls[] = array_merge($url,$this->urls); + } + else { + $this->urls[] = $url; + } } // manual_url_add @@ -118,6 +123,19 @@ class Stream { } // get_session /** + * set_session + * This overrides the normal session value, without adding + * an additional session into the database, should be called + * with care + */ + public static function set_session($sid) { + + self::$session_inserted = true; + self::$session=$sid; + + } // set_session + + /** * insert_session * This inserts a row into the session_stream table */ @@ -225,15 +243,9 @@ class Stream { asort($this->urls); /* Foreach songs */ - foreach ($this->songs as $song_id) { - // If it's a place-holder - if ($song_id == '-1') { - echo array_pop($this->urls) . "\n"; - continue; - } - $song = new Song($song_id); - if ($song->type == ".flac") { $song->type = ".ogg"; } - echo $song->get_url(); + foreach ($this->media as $element) { + $type = array_shift($element); + echo call_user_func(array($type,'play_url'),array_shift($element)) . "\n"; } // end foreach /* Foreach the additional URLs */ @@ -256,21 +268,29 @@ class Stream { header("Content-Type: audio/x-mpegurl;"); echo "#EXTM3U\n"; - // Flip for the popping - asort($this->urls); - // Foreach the songs in this stream object - foreach ($this->songs as $song_id) { - if ($song_id == '-1') { - echo "#EXTINF: URL-Add\n"; - echo array_pop($this->urls) . "\n"; - continue; + foreach ($this->media as $element) { + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); + switch ($type) { + case 'song': + echo "#EXTINF:$media->time," . $media->f_artist_full . " - " . $media->title . "\n"; + break; + case 'video': + echo "#EXTINF: Video - $media->title\n"; + break; + case 'radio': + echo "#EXTINF: Radio - $media->name [$media->frequency] ($media->site_url)\n"; + break; + case 'random': + echo "#EXTINF:Random URL\n"; + break; + default: + echo "#EXTINF:URL-Add\n"; + break; } - $song = new Song($song_id); - $song->format(); - - echo "#EXTINF:$song->time," . $song->f_artist_full . " - " . $song->title . "\n"; - echo $song->get_url(self::$session) . "\n"; + echo call_user_func(array($type,'play_url'),$media->id) . "\n"; } // end foreach /* Foreach URLS */ @@ -289,23 +309,34 @@ class Stream { public function create_pls() { /* Count entries */ - $total_entries = count($this->songs) + count($this->urls); + $total_entries = count($this->media) + count($this->urls); // Send the client a pls playlist header("Cache-control: public"); - header("Content-Disposition: filename=ampache-playlist.pls"); + header("Content-Disposition: filename=ampache_playlist.pls"); header("Content-Type: audio/x-scpls;"); echo "[Playlist]\n"; echo "NumberOfEntries=$total_entries\n"; - foreach ($this->songs as $song_id) { + foreach ($this->media as $element) { $i++; - $song = new Song($song_id); - $song->format(); - $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type; - $song_url = $song->get_url(self::$session); - echo "File" . $i . "=$song_url\n"; - echo "Title" . $i . "=$song_name\n"; - echo "Length" . $i . "=$song->time\n"; + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); + switch ($type) { + case 'song': + $name = $media->f_artist_full . " - " . $media->title . "." . $media->type; + $length = $media->time; + break; + default: + $name = 'URL-Add'; + $length='-1'; + break; + } + + $url = call_user_func(array($type,'play_url'),$media->id); + echo "File" . $i . "=$url\n"; + echo "Title" . $i . "=$name\n"; + echo "Length" . $i . "=$length\n"; } // end foreach songs /* Foreach Additional URLs */ @@ -328,21 +359,31 @@ class Stream { public function create_asx() { header("Cache-control: public"); - header("Content-Disposition: filename=playlist.asx"); + header("Content-Disposition: filename=ampache_playlist.asx"); header("Content-Type: audio/x-ms-wmv;"); echo "<ASX version = \"3.0\" BANNERBAR=\"AUTO\">\n"; echo "<TITLE>Ampache ASX Playlist</TITLE>"; - foreach ($this->songs as $song_id) { - $song = new Song($song_id); - $song->format(); - $url = $song->get_url(self::$session); - $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type; - + foreach ($this->media as $element) { + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); + switch ($type) { + case 'song': + $name = $media->f_album_full . " - " . $media->title . "." . $media->type; + $author = $media->f_artist_full; + break; + default: + $author = 'Ampache'; + $name = 'URL-Add'; + break; + } // end switch + $url = call_user_func(array($type,'play_url'),$media->id); + echo "<ENTRY>\n"; - echo "<TITLE>".$song->f_album_full ." - ". $song->f_artist_full ." - ". $song->title ."</TITLE>\n"; - echo "<AUTHOR>".$song->f_artist_full."</AUTHOR>\n"; + echo "<TITLE>$name</TITLE>\n"; + echo "<AUTHOR>$author</AUTHOR>\n"; echo "<REF HREF = \"". $url . "\" />\n"; echo "</ENTRY>\n"; @@ -374,40 +415,41 @@ class Stream { } // Itterate through the songs - foreach ($this->songs as $song_id) { - - $song = new Song($song_id); - $song->format(); + foreach ($this->media as $element) { + $type = array_shift($element); + $media = new $type(array_shift($element)); + + switch ($type) { + case 'song': + $xml['track']['title'] = $media->title; + $xml['track']['creator'] = $media->f_artist_full; + $xml['track']['info'] = Config::get('web_path') . "/albums.php?action=show&album=" . $media->album; + $xml['track']['image'] = Config::get('web_path') . "/image.php?id=" . $media->album . "&thumb=3&sid=" . session_id(); + $xml['track']['album'] = $media->f_album_full; + $length = $media->time; + break; + default: + + break; + } // type $xml = array(); - $xml['track']['location'] = $song->get_url(self::$session) . $flash_hack; + $xml['track']['location'] = call_user_func($type,'play_url',$media->id) . $flash_hack; $xml['track']['identifier'] = $xml['track']['location']; - $xml['track']['title'] = $song->title; - $xml['track']['creator'] = $song->f_artist_full; - $xml['track']['info'] = Config::get('web_path') . "/albums.php?action=show&album=" . $song->album; - $xml['track']['image'] = Config::get('web_path') . "/image.php?id=" . $song->album . "&thumb=3&sid=" . session_id(); - $xml['track']['album'] = $song->f_album_full; - $xml['track']['duration'] = $song->time * 1000; - $result .= xml_from_array($xml,1,'xspf'); + $xml['track']['duration'] = $length * 1000; - } // end foreach + $result .= xmlData::keyed_array($xml,1); - foreach ($this->urls as $url) { - $xml = array(); - $xml['track']['location'] = $url . $flash_hack; - $xml['track']['identifier'] = $url . $flash_hack; - $xml['track']['title'] = _('Ampache'); - $xml['track']['creator'] = _('Random'); - $xml['track']['duration'] = 9000; - $result .= xml_from_array($xml,1,'xspf'); - } + } // end foreach + + xmlData::set_type('xspf'); header("Cache-control: public"); header("Content-Disposition: filename=ampache-playlist.xspf"); header("Content-Type: application/xspf+xml; charset=utf-8"); - echo xml_get_header('xspf'); + echo xmlData::header(); echo $result; - echo xml_get_footer('xspf'); + echo xmlData::footer(); } // create_xspf @@ -466,18 +508,21 @@ class Stream { // First figure out what their current one is and create the object $localplay = new Localplay(Config::get('localplay_controller')); $localplay->connect(); - //HACK!!! - // Yea.. you know the baby jesus... he's crying right meow - foreach ($this->songs as $song_id) { - if ($song_id > 0) { - $song = new Song($song_id); - $localplay->add($song); - } - else { - $url = array_shift($this->urls); - $localplay->add($url); - } - } + foreach ($this->media as $element) { + $type = array_shift($element); + switch ($type) { + case 'video': + // Add check for video support + case 'song': + case 'radio': + $media = new $type(array_shift($element)); + break; + default: + $media = array_shift($element); + break; + } // switch on types + $localplay->add($media); + } // foreach object $localplay->play(); @@ -492,7 +537,7 @@ class Stream { $democratic = Democratic::get_current_playlist(); $democratic->set_parent(); - $democratic->vote($this->songs); + $democratic->vote($this->media); } // create_democratic @@ -504,7 +549,7 @@ class Stream { private function create_download() { // Build up our object - $song_id = $this->songs['0']; + $song_id = $this->media['0']; $song = new Song($song_id); $url = $song->get_url(); @@ -526,7 +571,7 @@ class Stream { header("Cache-control: public"); header("Content-Disposition: filename=playlist.ram"); header("Content-Type: audio/x-pn-realaudio ram;"); - foreach ($this->songs as $song_id) { + foreach ($this->media as $song_id) { $song = new Song($song_id); echo $song->get_url(); } // foreach songs @@ -755,7 +800,7 @@ class Stream { * get_base_url * This returns the base requirements for a stream URL this does not include anything after the index.php?sid=???? */ - public static function get_base_url($session_id='',$force_http='') { + public static function get_base_url() { if (Config::get('require_session')) { $session_string = 'sid=' . Stream::get_session() . '&'; @@ -763,7 +808,7 @@ class Stream { $web_path = Config::get('web_path'); - if (Config::get('force_http_play') OR !empty($force_http)) { + if (Config::get('force_http_play') OR !empty(self::$force_http)) { $port = Config::get('http_port'); if (preg_match("/:\d+/",$web_path)) { $web_path = str_replace("https://", "http://",$web_path); |