url = $url; $this->password = $password; } function execute($command,$params = null){ $retries = $this->retries; $params = dse_array($params,'&','='); $params['p'] = $this->password; foreach($params as &$param) $param = rawurlencode($param); $url = "http://{$this->url}/$command?" . dse_implode_with_key('=','&',$params); while($retries--){ try{ $result = @file_get_contents($url); if($result !== false) return $result; } catch(Exception $e){ } usleep($this->retry_sleep); } return false; } function info($info = 0){ //get info, see WINAMP_INFO_... constants return $this->execute('getinfo',array('info' => $info)); } function restart(){ //restart WinAmp and HttpQ return $this->execute('restart'); } function clean(){ return $this->execute('setclean'); } function chdir($dir){ //change the current working directory return $this->execute('chdir',array('dir' => $dir)); } function delete($index = null){ //delete the item at $index, or the entire playlist if null return ($index === null ? $this->execute('delete') : $this->execute('deletepos',array('index' => $index))); } //exec_visual //flushplaylist -- what is this doing? function getEqBand($band){ //get level (0..63) of one specific equalizer band (0..9) return $this->execute('geteqdata',array('band' => $band)); } function getEq(&$enabled = false){ //get levels of all equalizer bands in an array; use optional $enabled to see if the equalizer is active if($eq = dse_array($this->execute('geteqdatum',array('delim' => ',')),',')){ $enabled = $eq[10]; return array_slice($eq,0,10); } return false; } function setEqBand($band,$level){ //set level (0..63) of one specific equalizer band (0..9) return $this->execute('seteqdata',array('band' => $band,'level' => $level)); } function setEq($eq,$enabled = true){ //set levels of all equalizer bands; use $enabled to enable/disable equalizer if(count($eq) != 10) return false; $eq[] = $eq[] = intval($enabled); return $this->execute('seteqdatum',array('levels' => implode(',',$eq))); } function listCount(){ //number of items in playlist return $this->execute('getlistlength'); } function playlist($titles = false){ //return all filenames/titles in the playlist if($list = $this->execute($titles ? 'getplaylisttitlelist' : 'getplaylistfilelist',array('delim' => "\n"))) $list = dse_array($list,"\n"); return $list; } function indexOf($filename){ //return index of $filename; false if not found return array_search($filename,$this->playlist()); } function enqueue($filename,$title = null){ //add a $filename to the playlist; if $title is empty the name part of the $filename is taken if(!$title){ $title = basename($filename); if($i = strrpos($title,'.')) $title = substr($title,0,$i); } return $this->execute('enqueuefile',array('file' => $filename,'title' => $title)); } //enqueueurl function filename($index = null){ //return filename of file at $index, or current playing file if null return $this->execute('getplaylistfile',$index === null ? null : array('index' => $index)); } function title($index = null){ //return tile of file at $index, or current playing file if null return $this->execute('getplaylisttitle',$index === null ? null : array('index' => $index)); } function swap($from,$to = 0){ //swap files $from and $to in the playlist if($from == $to) return true; return $this->execute('swappos',array('from' => $from,'to' => $to)); } function hash($index = null){ //get md5 hash of file at $index, or the entire playlist if null return $this->execute('gethash',$index === null ? null : array('index' => $index)); } function id3tag($index = null,$v2 = false){ //get id3(v2) tags of file at $index, or current playing file if null $params = array('tags' => 't,a,y,g,l,c,r' . ($v2 ? ',m,s,p,o,i,u,e,b' : ''),'delim' => "\n"); if($index !== null) $params['index'] = $index; $tags = $this->execute($v2 ? 'getid3v2tag' : 'getid3tag',$params); if(!$tags) return false; return array_combine(array_merge(array('Title','Artist','Year','Genre','Album','Comment','Track'),$v2 ? array('AlbumArtist','Composer','Publisher','OriginalArtist','Copyright','Url','Encoded','Bpm') : array()),dse_array($tags,"\n")); } //hasid3(v2)tag -- just query 'm and see if any error //internet function mpegInfo($index = null){ //get mpeg info of file at $index, or current playing file if null $params = array('info' => 's,t,v,l,f,b,m,c,y,o,e','delim' => "\n"); if($index !== null) $params['index'] = $index; $info = $this->execute('getmpeginfo',$params); if(!$info) return false; return array_combine(array('Size','Time','Version','Layer','SampleFreq','Kbps','Mode','Crc','Copyrighted','Original','Emphasis'),dse_array($info,"\n")); //Time in seconds } function time($total = false){ //return current playing time or total time in seconds (float) $time = $this->execute('getoutputtime',array('frmt' => intval($total))); if(($time > 0) && !$total) $time /= 1000; return $time; } function jumpTo($time){ //jump to $time (seconds, float) return $this->execute('jumptotime',array('ms' => round($time * 1000))); } function prev(){ return $this->execute('prev'); } function play($filename = null){ //play the $filename (in current dir or absolute path), or play current file if empty (eg after pause) if($filename){ if($list = $this->playlist()) $index = array_search($filename,$list); else $index = false; if($index === false){ $this->execute('playfile',array('file' => $filename)); $index = count($list); } $this->listIndex = $index; $this->stop(); $this->play(); } else return $this->execute('play'); } //playurl function pause(){ return $this->execute('pause'); } function stop($fade = false){ //stop playing (with $fade) return $this->execute($fade ? 'fadeoutandstop' : 'stop'); } function next(){ return $this->execute('next'); } //shoutcast_connect //shoutcast_status function update(){ //update information for current title $this->execute('updatecurrenttitle'); } function validPassword(){ //returns true if the password is valid return $this->execute('validate_password'); } function relVolume($up = true){ //turn the volume up or down return $this->execute($up ? 'volumeup' : 'volumedown'); } function __get($property){ switch($property){ case 'listIndex': $property = 'listpos'; case 'autoService': case 'currentTitle': case 'dirty': case 'version': case 'volume': return $this->execute('get' . strtolower($property)); case 'playing': return $this->execute('is' . $property); case 'repeat': case 'shuffle': return $this->execute($property . '_status'); case 'eq': return $this->getEq(); default: return false; } } function __set($property,$value){ switch($property){ case 'autoService': $property = 'set' . $property; case 'repeat': case 'shuffle': $param = 'enable'; $value = intval($value); break; case 'volume': $property = 'set' . $property; $param = 'level'; break; case 'listIndex': $property = 'setplaylistpos'; $param = 'index'; break; case 'eq': return $this->setEq($value); default: return false; } return $this->execute(strtolower($property),array($param => $value)); } } ?>