コード例 #1
0
ファイル: NativeStream.php プロジェクト: ninjasilicon/core
 public function setUp()
 {
     if (!function_exists('smbclient_state_new')) {
         $this->markTestSkipped('libsmbclient php extension not installed');
     }
     $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
     $this->server = new NativeServer($this->config->host, $this->config->user, $this->config->password);
     $this->share = $this->server->getShare($this->config->share);
     if ($this->config->root) {
         $this->root = '/' . $this->config->root . '/' . uniqid();
     } else {
         $this->root = '/' . uniqid();
     }
     $this->share->mkdir($this->root);
 }
コード例 #2
0
ファイル: smb.php プロジェクト: evanjt/core
 public function __construct($params)
 {
     if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) {
         if (Server::NativeAvailable()) {
             $this->server = new NativeServer($params['host'], $params['user'], $params['password']);
         } else {
             $this->server = new Server($params['host'], $params['user'], $params['password']);
         }
         $this->share = $this->server->getShare(trim($params['share'], '/'));
         $this->root = isset($params['root']) ? $params['root'] : '/';
         if (!$this->root || $this->root[0] != '/') {
             $this->root = '/' . $this->root;
         }
         if (substr($this->root, -1, 1) != '/') {
             $this->root .= '/';
         }
     } else {
         throw new \Exception('Invalid configuration');
     }
 }
コード例 #3
0
ファイル: sonos3.class.php プロジェクト: eliovir/plugin-sonos
 public function execute($_options = array())
 {
     if ($this->getType() == 'info') {
         return;
     }
     try {
         $eqLogic = $this->getEqLogic();
         $sonos = sonos3::getSonos();
         $controller = sonos3::getControllerByIp($eqLogic->getLogicalId());
         if ($this->getLogicalId() == 'play') {
             if ($eqLogic->getConfiguration('model') == 'PLAYBAR') {
                 $state = $eqLogic->getCmd(null, 'state');
                 $track_title = $eqLogic->getCmd(null, 'track_title');
                 if (is_object($state) && is_object($track_title)) {
                     if ($track_title->execCmd(null, 2) == __('Aucun', __FILE__) && $state->execCmd(null, 2) == __('Lecture', __FILE__)) {
                         return $controller->unmute();
                     }
                 }
             }
             $controller->play();
         }
         if ($this->getLogicalId() == 'stop') {
             if ($eqLogic->getConfiguration('model') == 'PLAYBAR') {
                 $state = $eqLogic->getCmd(null, 'state');
                 $track_title = $eqLogic->getCmd(null, 'track_title');
                 if (is_object($state) && is_object($track_title)) {
                     if ($track_title->execCmd(null, 2) == __('Aucun', __FILE__) && $state->execCmd(null, 2) == __('Lecture', __FILE__)) {
                         return $controller->mute();
                     }
                 }
             }
             $controller->pause();
         }
         if ($this->getLogicalId() == 'pause') {
             if ($eqLogic->getConfiguration('model') == 'PLAYBAR') {
                 $state = $eqLogic->getCmd(null, 'state');
                 $track_title = $eqLogic->getCmd(null, 'track_title');
                 if (is_object($state) && is_object($track_title)) {
                     if ($cmd_track_title->execCmd(null, 2) == __('Aucun', __FILE__) && $state->execCmd(null, 2) == __('Lecture', __FILE__)) {
                         return $controller->mute();
                     }
                 }
             }
             $controller->pause();
         }
         if ($this->getLogicalId() == 'previous') {
             $controller->previous();
         }
         if ($this->getLogicalId() == 'next') {
             $controller->next();
         }
         if ($this->getLogicalId() == 'mute') {
             $controller->mute();
         }
         if ($this->getLogicalId() == 'unmute') {
             $controller->unmute();
         }
         if ($this->getLogicalId() == 'repeat') {
             $controller->setRepeat(!$controller->getRepeat());
         }
         if ($this->getLogicalId() == 'shuffle') {
             $controller->setShuffle(!$controller->getShuffle());
         }
         if ($this->getLogicalId() == 'setVolume') {
             if ($_options['slider'] < 0) {
                 $_options['slider'] = 0;
             }
             if ($_options['slider'] > 100) {
                 $_options['slider'] = 100;
             }
             $controller->setVolume($_options['slider']);
         }
         if ($this->getLogicalId() == 'play_playlist') {
             if (!$controller->isUsingQueue()) {
                 $controller->useQueue();
             }
             $queue = $controller->getQueue();
             $playlist = $sonos->getPlaylistByName(trim(trim($_options['title']), '"'));
             if ($playlist == null) {
                 foreach ($sonos->getPlaylists() as $playlist_search) {
                     if (str_replace('  ', ' ', $playlist_search->getName()) == $_options['title']) {
                         $playlist = $playlist_search;
                         break;
                     }
                 }
             }
             if ($playlist == null) {
                 throw new Exception(__('Playlist non trouvé : ', __FILE__) . trim($_options['title']));
             }
             $tracks = $playlist->getTracks();
             $queue->clear();
             if (count($tracks) > 1) {
                 if (isset($_options['message']) && $_options['message'] == 'random') {
                     shuffle($tracks);
                 }
                 $queue->addTrack($tracks[0]);
                 $controller->play();
                 unset($tracks[0]);
                 $queue->addTracks($tracks);
             } else {
                 $queue->addTracks($tracks);
                 $controller->play();
             }
         }
         if ($this->getLogicalId() == 'play_radio') {
             $radio = $sonos->getRadio();
             $stations = $radio->getFavouriteStations();
             if ($stations->getName() == $_options['title']) {
                 $controller->useStream($show)->play();
             }
         }
         if ($this->getLogicalId() == 'add_speaker') {
             $speaker = $sonos->getSpeakerByRoom($_options['title']);
             $controller->addSpeaker($speaker);
         }
         if ($this->getLogicalId() == 'remove_speaker') {
             $speaker = $sonos->getSpeakerByRoom($_options['title']);
             $controller->removeSpeaker($speaker);
         }
         if ($this->getLogicalId() == 'tts') {
             $path = explode('/', trim(config::byKey('tts_path', 'sonos3'), '/'));
             $server = new Server(config::byKey('tts_host', 'sonos3'), config::byKey('tts_username', 'sonos3'), config::byKey('tts_password', 'sonos3'));
             $share = $server->getShare($path[0]);
             $adapter = new SmbAdapter($share);
             $filesystem = new Filesystem($adapter);
             $folder = array_pop($path);
             $directory = new Directory($filesystem, config::byKey('tts_host', 'sonos3') . '/' . implode('/', $path), $folder);
             if (config::byKey('ttsProvider', 'sonos3') != 'voxygen' && strlen($_options['message']) > 100) {
                 $_options['message'] = substr($_options['message'], 0, 100);
             }
             $track = new TextToSpeech(trim($_options['message']), $directory, new GoogleProvider());
             $track->setLanguage("fr");
             $track->setProvider(new VoxygenProvider());
             $track->getProvider()->setVoice(config::byKey('ttsVoxygenVoice', 'sonos3', 'Helene'));
             if ($_options['title'] != '' && is_numeric($_options['title'])) {
                 $controller->interrupt($track, $_options['title']);
             } else {
                 $controller->interrupt($track);
             }
         } else {
             sonos3::pull($eqLogic->getId());
         }
     } catch (Exception $e) {
         log::add('sonos', 'info', $e->getMessage());
     }
 }
コード例 #4
0
ファイル: example.php プロジェクト: Masterfion/plugin-sonos
<?php

use Icewind\SMB\NativeServer;
use Icewind\SMB\Server;
require 'vendor/autoload.php';
if (Server::NativeAvailable()) {
    $server = new NativeServer('localhost', 'test', 'test');
} else {
    $server = new Server('localhost', 'test', 'test');
}
$share = $server->getShare('test');
$share->put(__FILE__, 'example.php');
$files = $share->dir('/');
foreach ($files as $file) {
    echo $file->getName() . "\n";
}