diff options
-rw-r--r-- | config/ampache.cfg.php.dist | 23 | ||||
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/class/song.class.php | 61 | ||||
-rw-r--r-- | lib/init.php | 10 | ||||
-rw-r--r-- | lib/stream.lib.php | 15 | ||||
-rw-r--r-- | play/index.php | 43 |
6 files changed, 84 insertions, 69 deletions
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist index 203b8c3e..2780c309 100644 --- a/config/ampache.cfg.php.dist +++ b/config/ampache.cfg.php.dist @@ -470,18 +470,27 @@ downsample_cmd = mp3splt -qnf %FILE% %OFFSET% %EOF% -o - | lame --mp3input -q 3 ####################################################### # These are commands used to transcode non-streaming -# formats to mp3 for streaming. Very similar to -# downsampling, but requires something that can play -# the various file formats. +# formats to the target file type for streaming. Any +# file types defined here will automatically be transcoded +# using the stream_cmd_??? regardless of personal preferences +# This can be usefull in re-encoding file types that don't stream +# very well, or if the player doesn't support some file types. +# REQUIRED variables +# transcode_TYPE = true +# transcode_TYPE_target = TARGET_FILE_TYPE +# stream_cmd_TYPE = TRANSCODE_COMMAND # List of filetypes to transcode -transcode_m4a = true -transcode_flac = true -#transcode_mpc = false +transcode_m4a = true +transcode_m4a_target = mp3 +transcode_flac = true +transcode_flac_target = mp3 +#transcode_mpc = false +#transcode_mpc_target = mp3 # These are the commands that will be run to transcode the file stream_cmd_flac = flac -dc %FILE% | lame -r -b 128 -S - - -stream_cmd_m4a = faad -f 2 -w %FILE% | lame -r -b 128 -S - - +stream_cmd_m4a = faad -f 2 -w %FILE% | lame -r -b 128 -S - - #stream_cmd_mpc = ####################################################### diff --git a/docs/CHANGELOG b/docs/CHANGELOG index e19a937e..8c215a41 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.3.3-Beta3 + - Fixed some logic errors in the Transcoding logic and play logic - Rewrote Album Art collection to correct some seriou logic flaws - Added potential fix for FastCGI installations - Updated Snoopy to 1.2.3 (from manually patched 1.2.1) diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 06ca5d54..0e11a3fe 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -152,11 +152,17 @@ class Song { play, used to set mime headers and to trick players into playing them correctly */ - function format_type() { + function format_type($override='') { - preg_match('/\.([A-Za-z0-9]+)$/', $this->file,$results); + // If we pass an override for downsampling or whatever then use it + if (!empty($override)) { + $this->type = $override; + } + else { + preg_match('/\.([A-Za-z0-9]+)$/', $this->file,$results); + $this->type = strtolower($results['1']); + } - $this->type = strtolower($results['1']); switch ($this->type) { case 'spx': @@ -654,6 +660,20 @@ class Song { */ function format_song() { + $this->format(); + + return true; + + } + + /** + * format + * This takes the current song object + * and does a ton of formating on it creating f_??? variables on the current + * object + */ + function format() { + // Format the filename preg_match("/^.*\/(.*?)$/",$this->file, $short); $this->f_file = htmlspecialchars($short[1]); @@ -820,31 +840,18 @@ class Song { function native_stream() { if ($this->_transcode) { return false; } + + $conf_var = 'transcode_' . $this->type; + $conf_type = 'transcode_' . $this->type . '_target'; + + if (conf($conf_var)) { + $this->_transcode = true; + $this->format_type(conf($conf_type)); + debug_event('auto_transcode','Transcoding to ' . conf($conf_type),'5'); + return false; + } - switch ($this->type) { - //TODO: fill out these cases once we have it working for m4a - case 'm4a': - if (conf('transcode_m4a')) { break; } - return true; - break; - case 'flac': - if (conf('transcode_flac')) { break; } - return true; - break; - case 'mpc': - if (conf('transcode_mpc')) { break; } - return true; - break; - default: - return true; - break; - } // end switch - - /* If we've made it this far then we must be trying to transcode */ - $this->_transcode = true; - $this->format_type(); - - return false; + return true; } // end native_stream diff --git a/lib/init.php b/lib/init.php index b7fbdac1..5e96e204 100644 --- a/lib/init.php +++ b/lib/init.php @@ -256,9 +256,13 @@ if (in_array("http",$results['auth_methods'])) { } // end if http auth +if ($no_session) { + define('NO_SESSION','1'); +} + // If we don't want a session -if (!isset($no_session) AND conf('use_auth')) { +if (NO_SESSION != '1' AND conf('use_auth')) { /* Verify Their session */ if (!vauth_check_session()) { logout(); exit; } @@ -302,10 +306,6 @@ else { init_preferences(); } -/* PHP5 Date problem solved.. ya'll GMT now! */ -$timezone = "TZ=" . conf('time_zone'); -putenv($timezone); - /* Add in some variables for ajax done here because we need the user */ $ajax_info['ajax_url'] = $results['web_path'] . '/server/ajax.server.php'; $ajax_info['ajax_info'] = '&user_id=' . $user->id . '&sessid=' . session_id(); diff --git a/lib/stream.lib.php b/lib/stream.lib.php index 8049be8b..cb935aaf 100644 --- a/lib/stream.lib.php +++ b/lib/stream.lib.php @@ -122,6 +122,7 @@ function check_lock_songs($song_id) { $db_results = mysql_query($sql, dbh()); if (mysql_num_rows($db_results)) { + debug_event('lock_songs','Song Already Playing, skipping...','5'); return false; } @@ -139,18 +140,6 @@ function check_lock_songs($song_id) { */ function start_downsample($song,$now_playing_id=0,$song_name=0) { - /** - * Extra check, for now hardcode it to mp3 but if - * we are transcoding we need to fix the mime type - * and let the user define what file type it's switching - * to. - */ - if (!$song->native_stream()) { - $song->mime = 'audio/mpeg'; - $song_name = $song->f_artist_full . " - " . $song->title . ".mp3"; - } - - /* Check to see if bitrates are set if so let's go ahead and optomize! */ $max_bitrate = conf('max_bit_rate'); $min_bitrate = conf('min_bit_rate'); @@ -252,7 +241,7 @@ function start_downsample($song,$now_playing_id=0,$song_name=0) { /* We need more than just the handle here */ $return_array['handle'] = $fp; - $return_array['size'] = $sample_ration*$song->size; + $return_array['size'] = $sample_ratio*$song->size; return ($return_array); diff --git a/play/index.php b/play/index.php index 280636eb..95f92344 100644 --- a/play/index.php +++ b/play/index.php @@ -23,10 +23,10 @@ This is the wrapper for opening music streams from this server. This script will play the local version or redirect to the remote server if that be the case. Also this will update local statistics for songs as well. - + This is also where it decides if you need to be downsampled. */ -$no_session = true; +define('NO_SESSION','1'); require_once('../lib/init.php'); require_once(conf('prefix') . '/modules/horde/Browser.php'); @@ -39,12 +39,17 @@ $sid = scrub_in($_REQUEST['sid']); /* This is specifically for tmp playlist requests */ $tmp_id = scrub_in($_REQUEST['tmp_id']); -/* First things first, if we don't have a uid stop here */ -if (!isset($uid)) { +/* First things first, if we don't have a uid/song_id stop here */ +if (empty($song_id) && empty($tmp_id)) { debug_event('no_song',"Error: No Song UID Specified, nothing to play",'2'); exit; } +if (!isset($uid)) { + debug_event('no_usre','Error: No User specified','2'); + exit; +} + /* Misc Housework */ $dbh = dbh(); $user = new User($uid); @@ -55,8 +60,8 @@ if (conf('xml_rpc')) { if (conf('require_session') OR $xml_rpc) { if(!session_exists($sid,$xml_rpc)) { - die(_("Session Expired: please log in again at") . " " . conf('web_path') . "/login.php"); debug_event('session_expired',"Streaming Access Denied: " . $GLOBALS['user']->username . "'s session has expired",'3'); + die(_("Session Expired: please log in again at") . " " . conf('web_path') . "/login.php"); } // Now that we've confirmed the session is valid @@ -80,6 +85,7 @@ if (conf('access_control')) { !$access->check('network',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->username,'25')) { debug_event('access_denied', "Streaming Access Denied: " . $_SERVER['REMOTE_ADDR'] . " does not have stream level access",'3'); access_denied(); + exit; } } // access_control is enabled @@ -94,7 +100,6 @@ if ($tmp_id) { $song_id = $tmp_playlist->get_next_object(); } - /* Base Checks passed create the song object */ $song = new Song($song_id); $song->format_song(); @@ -188,17 +193,7 @@ if (conf('stream_name_format')) { else { $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type; } - - -// Send file, possible at a byte offset -$fp = @fopen($song->file, 'rb'); - -if (!is_resource($fp)) { - debug_event('file_read_error',"Error: Unable to open $song->file for reading",'2'); - cleanup_and_exit($lastid); -} - $startArray = sscanf( $_SERVER[ "HTTP_RANGE" ], "bytes=%d-" ); $start = $startArray[0]; @@ -220,15 +215,28 @@ if (conf('access_control') AND conf('downsample_remote')) { $not_local = true; } } // if access_control + + if ($GLOBALS['user']->prefs['play_type'] == 'downsample' || !$song->native_stream() || $not_local) { + debug_event('downsample','Starting Downsample...','5'); $results = start_downsample($song,$lastid,$song_name); $fp = $results['handle']; $song->size = $results['size']; } // end if downsampling +else { + // Send file, possible at a byte offset + $fp = fopen($song->file, 'rb'); + +if (!is_resource($fp)) { + debug_event('file_read_error',"Error: Unable to open $song->file for reading",'2'); + cleanup_and_exit($lastid); + } +} // else not downsampling -elseif ($start) { +if ($start) { + debug_event('seek','Start point recieved, skipping ahead in the song...','5'); $browser->downloadHeaders($song_name, $song->mime, false, $song->size); fseek( $fp, $start ); $range = $start ."-". ($song->size-1) . "/" . $song->size; @@ -239,6 +247,7 @@ elseif ($start) { /* Last but not least pump em out */ else { + debug_event('stream','Starting stream of ' . $song->file . ' with size ' . $song->size,'5'); header("Content-Length: $song->size"); $browser->downloadHeaders($song_name, $song->mime, false, $song->size); } |