$show = $showList->offsetGet($key); $showTitle = $show->getShowTitle(); $episodeTitle = $show->getEpisodeTitle(); $showURL = $show->getURL(); print " > Picked a random show from the list.\n"; print " > - {$showTitle} {$episodeTitle}\n"; print " > - {$showURL}\n"; // Identify local file locations to be deleted later. $tivoFile = '/tmp/' . rand() . '.tivo'; $mpegFile = '/tmp/' . rand() . '.mpeg'; // Download a preview file. validateClass('JimLind\\TiVo\\VideoDownloader'); print " > Downloading a preview of the show locally.\n"; $videoDownloader = new JimLind\TiVo\VideoDownloader($mak, $guzzle); $videoDownloader->setLogger($logger); $videoDownloader->downloadPreview($showURL, $tivoFile); //readfile($tivoFile); // Verify file exists and has contents. if (file_exists($tivoFile) && filesize($tivoFile) > 0) { print " > Preview file was sucessfully downloaded.\n"; } else { print " > Preview file was not sucessfully downloaded.\n"; finishRun($logFile); } // Decode the preview file. validateClass('JimLind\\TiVo\\VideoDecoder'); print " > Decoding the preview of the local show file.\n"; $videoDecoder = new JimLind\TiVo\VideoDecoder($mak, $builder); $videoDecoder->setLogger($logger); $videoDecoder->decode($tivoFile, $mpegFile); // Verify file exists and has contents.
// This is the best PHP HTTP library around. $guzzle = new GuzzleHttp\Client(); // Use the TiVoFinder service to find a TiVo on your local network. // If it can't find a TiVo for whatever reason it'll return an empty string. // If you have more than one TiVo it'll return the IP of the first one it sees. $tivoFinder = new JimLind\TiVo\TiVoFinder($builder); $ipAddress = $tivoFinder->find(); // Use the XmlDownloader service to download a list of strings representing XML show documents. // Each show is a self contained valid XML string. // The TiVo IP address and MAK (Media Access Key) are needed here. $ip = '192.168.0.1'; $mak = '7678999999'; $xmlDownloader = new JimLind\TiVo\XmlDownloader($ip, $mak, $guzzle); $xmlList = $xmlDownloader->download(); // Use the ShowListFactory to create a list of Show objects. // The factory is setup specifically to use the data output from the NowPlaying service. $showListFactory = new JimLind\TiVo\Factory\ShowListFactory(); $showList = $showListFactory->createShowListFromXmlList($xmlList); // Grab one Show off the top. $show = $showList->offsetGet(0); // Setup the VideoDownloader service. // The TiVo IP address and MAK (Media Access Key) are needed here. $videoDownloader = new JimLind\TiVo\VideoDownloader($mak, $guzzle); // Download preview and complete files from TiVo. $videoDownloader->downloadPreview($show->getURL(), '/home/user/videos/raw_video_preview.tivo'); $videoDownloader->download($show->getURL(), '/home/user/videos/raw_video_complete.tivo'); // Use the VideoDecoder service to create an MPEG file from the encoded raw TiVo file. // It just writes the file to the new location. Doesn't touch the old file. // The MAK (Media Access Key) is needed here. $videoDecoder = new JimLind\TiVo\VideoDecoder($mak, $builder); $videoDecoder->decode('/home/user/videos/raw_video_preview.tivo', '/home/user/videos/raw_video_preview.mpeg');