start(); class PlaylistCli{ function PlaylistCli(){ $this->aLastSearchItems = array(); $this->end = false; $this->prompt = "> "; $this->host = new RokuClient(); $this->debug = false; $this->host->debug = $this->debug; } function start(){ $this->host->ensureServerConnection("rsp"); while( !$this->end ){ if( $this->debug ) echo "in loop\n"; $command = prompt( $this->prompt ); if( $this->debug ) echo "Command: ".$command."\n"; $this->parseCommand( $command ); } } function parseCommand( $command ){ if( trim( $command ) == "?" ){ echo $this->getHelp(); return true; } if( !preg_match( "/([sabticqilp]) (.+)$/", $command, $m ) ){ $this->aLastSearchItems = $this->host->SearchAll( $command ); $this->listLastSearch(); return true; } if( $this->debug ){ print_r( $m ); } switch( $m[1] ){ case "a": $this->aLastSearchItems = $this->host->SearchArtists( $m[2] ); $this->listLastSearch(); break; case "b": $this->aLastSearchItems = $this->host->SearchAlbums( $m[2] ); $this->listLastSearch(); break; case "t": $this->aLastSearchItems = $this->host->SearchSongs( $m[2] ); $this->listLastSearch(); break; case "c": $this->aLastSearchItems = $this->host->SearchComposers( $m[2] ); $this->listLastSearch(); break; case "i": $this->aLastSearchItems = $this->host->SearchAll( $m[2] ); $this->listLastSearch(); break; case "q": $this->queueTrack( $m[2] ); break; case "s": $this->savePlaylist( $m[2] ); break; case "l": $this->host->LoadPlaylist( $m[2] ); break; } } function savePlaylist( $name ){ $aIds = $this->host->GetNowPlayingSongIds(); $ff = new FireflyDb(); $ff->debug = $this->debug; $ff->savePlaylist( $name, $aIds ); } function listLastSearch(){ if( $this->debug ) echo "listLastSearch\n"; foreach( $this->aLastSearchItems as $key => $value ){ $aInfo = $this->host->GetSongInfo( $key ); $inf = ""; if( isset( $aInfo["artist"] ) ) $inf .= $aInfo["artist"]." - "; if( isset( $aInfo["title"] ) ) $inf .= $aInfo["title"]." "; if( isset( $aInfo["album"] ) ) $inf .= "(".$aInfo["album"].")"; echo $key.": ".$inf."\n"; } } function queueTrack( $track ){ if( sizeof( $this->aLastSearchItems ) == 0 ) return false; if( $track != "all" ){ if( intval( $track ) > sizeof( $this->aLastSearchItems ) ) return false; $aTracks = array(); $a = split( ",", $track ); foreach( $a as $s ){ $aRange = split( "-", $s ); if( isset( $aRange[1] ) ){ $start = intval( $aRange[0] ); $end = intval( $aRange[1] ); if( $start >= $end ) continue; for( $i=$start; $i<=$end; $i++ ){ $this->host->NowPlayingInsert( $i ); } }else{ $this->host->NowPlayingInsert( intval( $aRange[0] ) ); } } }else{ $this->host->NowPlayingInsert( $track ); } } function getHelp(){ $str = "Command syntax: a|b|t|g|i|q (search term|index)\n" ." a: Artist name\n" ." b: Album name\n" ." t: Title/Track name\n" ." c: Composer\n" ." i: Any track info\n" ." q: Queue track from search\n"; return $str; } } ?>