From 2829aa9f0a024c0d9bbd9d5cc8bd34e47c43b783 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 17 Nov 2020 12:49:41 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 45 +++++++++++---- config/remote.php | 19 +++---- scripts/lib/harmony.php | 2 +- scripts/lib/http.php | 15 +++-- scripts/lib/remoteinfos.php | 107 +++++++++++++++++++++++++----------- scripts/lib/scenes.php | 2 - scripts/lib/shield.php | 15 ++++- scripts/shield.php | 2 + 8 files changed, 141 insertions(+), 66 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 68a3f81..1ce4930 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,13 @@ + + + + + + + @@ -1289,12 +1310,12 @@ - + - + @@ -1322,11 +1343,11 @@ - + - + diff --git a/config/remote.php b/config/remote.php index 173414a..c9a33ac 100644 --- a/config/remote.php +++ b/config/remote.php @@ -37,21 +37,16 @@ $bricksShield = ['type' => 'shield', 'width' => 4, 'height' => 4, 'bricks' => [ ['type' => 'remote-shield-ok', 'width' => 1, 'height' => 1, 'top' => 2, 'left' => 2], ]]; -$bricksShieldMedia = ['type' => 'shieldmedia', 'width' => 5, 'height' => 4, 'bricks' => [ +$bricksShieldMedia = ['type' => 'shieldmedia', 'width' => 5, 'height' => 5, 'bricks' => [ ['type' => 'remote-volume', 'width' => 1, 'height' => 3, 'top' => 1, 'left' => 0], ['type' => 'remote-rew', 'width' => 1, 'height' => 1, 'top' => 0, 'left' => 0], - ['type' => 'remote-playpause', 'width' => 3, 'height' => 1, 'top' => 0, 'left' => 1], - ['type' => 'remote-light-down', 'width' => 1, 'height' => 1, 'top' => 1, 'left' => 3], - ['type' => 'remote-fwd', 'width' => 1, 'height' => 1, 'top' => 0, 'left' => 4], - ['type' => 'remote-up', 'width' => 1, 'height' => 1, 'top' => 1, 'left' => 2], - ['type' => 'remote-left', 'width' => 1, 'height' => 1, 'top' => 2, 'left' => 1], - ['type' => 'remote-down', 'width' => 1, 'height' => 1, 'top' => 3, 'left' => 2], - ['type' => 'remote-right', 'width' => 1, 'height' => 1, 'top' => 2, 'left' => 3], - ['type' => 'remote-shield-back', 'width' => 1, 'height' => 1, 'top' => 1, 'left' => 1], - ['type' => 'remote-shield-menu', 'width' => 1, 'height' => 1, 'top' => 1 + 2, 'left' => 1], - ['type' => 'remote-shield-home', 'width' => 1, 'height' => 1, 'top' => 1 + 2, 'left' => 1 + 2], - ['type' => 'remote-shield-ok', 'width' => 1, 'height' => 1, 'top' => 2, 'left' => 2], + ['type' => 'remote-playpause', 'width' => 2, 'height' => 1, 'top' => 0, 'left' => 1], + ['type' => 'remote-light-down', 'width' => 1, 'height' => 1, 'top' => 4, 'left' => 4], + ['type' => 'remote-fwd', 'width' => 1, 'height' => 1, 'top' => 0, 'left' => 3], + ['type' => 'remote-stop', 'width' => 1, 'height' => 1, 'top' => 0, 'left' => 4], + ['type' => 'remote-infos', 'width' => 3, 'height' => 3, 'top' => 1, 'left' => 1], ['type' => 'remote-subtitles', 'width' => 1, 'height' => 3, 'top' => 1, 'left' => 4], + ['type' => 'remote-timeline', 'width' => 4, 'height' => 1, 'top' => 4, 'left' => 0], ]]; diff --git a/scripts/lib/harmony.php b/scripts/lib/harmony.php index 83df419..6dfe74a 100644 --- a/scripts/lib/harmony.php +++ b/scripts/lib/harmony.php @@ -37,7 +37,7 @@ function harmonyActivity($activity) $current = getCurrentHarmonyActivity(); if ($current == 'off' || $current == 'poweroff' || !$current) { if ($activity == 'media' || $activity == 'shield' || $activity == 'tv') { - $wait = 30; + $wait = 10; } } if ($activity !== 'off' && $activity !== 'poweroff') { diff --git a/scripts/lib/http.php b/scripts/lib/http.php index adec6f4..cd99e87 100644 --- a/scripts/lib/http.php +++ b/scripts/lib/http.php @@ -31,12 +31,14 @@ function getHttpClient($newclient = false) /** * @param $url * @param string $method - * @param string $data + * @param array $data * @param null $auth + * @param int $timeout + * @param bool $allowRedirections + * @param array $headers * @return mixed|\Psr\Http\Message\ResponseInterface - * @throws \GuzzleHttp\Exception\GuzzleException */ -function httpRequest($url, $method = 'get', $data = [], $auth = null, $timeout = 10, $allowRedirections = true) +function httpRequest($url, $method = 'get', $data = [], $auth = null, $timeout = 10, $allowRedirections = true, $headers = []) { $method = mb_strtoupper($method); $client = getHttpClient(); @@ -47,8 +49,13 @@ function httpRequest($url, $method = 'get', $data = [], $auth = null, $timeout = if ($method == 'GET') { $options['query'] = $data; } else { - $options['form_params'] = $data; + if (is_string($data)) { + $options['body'] = $data; + } else { + $options['form_params'] = $data; + } } + $options['headers'] = $headers; return $client->request($method, $url, $options); } \ No newline at end of file diff --git a/scripts/lib/remoteinfos.php b/scripts/lib/remoteinfos.php index da2874e..cb64b91 100644 --- a/scripts/lib/remoteinfos.php +++ b/scripts/lib/remoteinfos.php @@ -7,17 +7,41 @@ function remoteInfos() if ($p == 'squeezebox') { $res = squeezeboxRemoteInfos(); } else { - if (($p === 'netflix' || $p === 'tv') && config('TVPLAYER') === 'shield') { - $res = ['type' => 'shield', 'can_seek' => false]; + if (config('TVPLAYER') === 'shield') { + if (shieldGetCurrentApp() === 'kodi') { + $res = ['type' => 'shieldmedia', 'can_seek' => true]; + $p = json_decode(httpRequest('http://' . getDevice()['shield'] . ':8754/jsonrpc?Base=1', 'post', '[{"jsonrpc":"2.0","method":"Player.GetProperties","params":[1,["playlistid","speed","position","totaltime","time","percentage","shuffled","repeat","canrepeat","canshuffle","canseek","partymode"]],"id":1},{"jsonrpc":"2.0","method":"Player.GetItem","params":[1,["title","thumbnail","file","artist","genre","year","rating","album","track","duration","playcount","dateadded","episode","artistid","albumid","tvshowid","fanart"]],"id":2}]', ['kodi', 'atacama'], 10, true, ['X-Requested-With' => 'XMLHttpRequest', 'Content-type' => 'application/json'])->getBody(), true); + $res['duration'] = ''; + $res['time'] = ''; + $res['title'] = ''; + $res['artwork'] = ''; + $res['status'] = ''; + if (isset($p[0]['result'])) { + $r = $p[0]['result']; + $res['can_seek'] = $r['canseek']; + $res['duration'] = 3600 * $r['totaltime']['hours'] + 60 * $r['totaltime']['minutes'] + $r['totaltime']['seconds']; + $res['time'] = 3600 * $r['time']['hours'] + 60 * $r['time']['minutes'] + $r['time']['seconds']; + } + if (isset($p[1]['result']['item']['file'])) { + $res = array_merge($res, getTitleAndArtwork($p[1]['result']['item']['file'])); + } + } else { + $res = ['type' => 'shield', 'can_seek' => false]; + } + } else { - if ($p == 'mediarasp') { - if (config('VIDEOPLAYER') === 'shield') { - $res = ['type' => 'shieldmedia', 'can_seek' => false]; + if (($p === 'netflix' || $p === 'tv') && config('TVPLAYER') === 'shield') { + $res = ['type' => 'shield', 'can_seek' => false]; + } else { + if ($p == 'mediarasp' || $p === 'shieldmedia') { + if (config('VIDEOPLAYER') === 'shield') { + $res = ['type' => 'shieldmedia', 'can_seek' => false]; + } else { + $res = mediaraspRemoteInfos(); + } } else { - $res = mediaraspRemoteInfos(); + $res = ['type' => $p, 'can_seek' => false]; } - } else { - $res = ['type' => $p, 'can_seek' => false]; } } } @@ -87,36 +111,53 @@ function mediaraspRemoteInfos() $res['title'] = $meta['title']; $res['artwork'] = $meta['thumbnail']; } else { - $file = str_replace('/nas', '/volume1/Share', $source); - if (file_exists($file . '.tmdb.id')) { - $id = file_get_contents($file . '.tmdb.id'); - if (intval($id) > 0) { - $library = new moviesLibrary($directories); - $movie = $library->getMovieByID($id); - $res['title'] = $movie['title']; - $res['artwork'] = cacheMedia('https://image.tmdb.org/t/p/w500' . $movie['backdrop_path']); - } - } else { - $f = new SplFileInfo($file); - preg_match('|S(\d{2})/S\d{2}E(\d{2})|', $f, $matches); - $tvid = $f->getPath() . '/../.tmdb.id'; - - if (file_exists($tvid)) { - $id = file_get_contents($tvid); - if (intval($id)) { - $library = new tvShowLibrary($directories); - $tvshow = $library->getTVShowById($id); - $res['title'] = $tvshow['name']; - if (count($matches) > 0) { - $res['title'] .= '
S' . $matches[1] . ' E' . $matches[2]; - } - $res['artwork'] = cacheMedia('https://image.tmdb.org/t/p/w500' . $tvshow['backdrop_path']); + $res = array_merge($res, getTitleAndArtwork($source)); + } + + return $res; +} + +function getTitleAndArtwork($source) +{ + global $directories; + $cachekey = 'title_artwork_' . sha1($source); + $cache = getState($cachekey, null); + if (null !== $cache) { + return json_decode($cache, true); + } + + $res = ['title' => '', 'artwork' => '']; + $file = str_replace('smb://Share:dcfyjbcyckwydtgufjx@192.168.13.4/Share/', '/volume1/Share', $source); + $file = str_replace('/nas', '/volume1/Share', $file); + if (file_exists($file . '.tmdb.id')) { + $id = file_get_contents($file . '.tmdb.id'); + if (intval($id) > 0) { + $library = new moviesLibrary($directories); + $movie = $library->getMovieByID($id); + $res['title'] = $movie['title']; + $res['artwork'] = cacheMedia('https://image.tmdb.org/t/p/w500' . $movie['backdrop_path']); + } + } else { + $f = new SplFileInfo($file); + preg_match('|S(\d{2})/S\d{2}E(\d{2})|', $f, $matches); + $tvid = $f->getPath() . '/../.tmdb.id'; + + if (file_exists($tvid)) { + $id = file_get_contents($tvid); + if (intval($id)) { + $library = new tvShowLibrary($directories); + $tvshow = $library->getTVShowById($id); + $res['title'] = $tvshow['name']; + if (count($matches) > 0) { + $res['title'] .= '
S' . $matches[1] . ' E' . $matches[2]; } + $res['artwork'] = cacheMedia('https://image.tmdb.org/t/p/w500' . $tvshow['backdrop_path']); } } } - + setState($cachekey, json_encode($res)); return $res; + } function squeezeboxRemoteInfos() diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 2c5060c..e7c95e4 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -498,8 +498,6 @@ $scenes = [ ['type' => 'ir', 'room' => 'bureausun', 'device' => 'Projector', 'command' => 'PowerOn'], ], 'bureau/media/stop' => [ - /* domoticzSwitch(1, false); - irsend('bureau', 'Projector', 'PowerOff');*/ ['type' => 'scene', 'scene' => 'bureau/screen/up'], ['type' => 'scene', 'scene' => 'bureau/rideaux/open'], ['type' => 'scene', 'scene' => 'bureau/auto'], diff --git a/scripts/lib/shield.php b/scripts/lib/shield.php index f8496b2..3686fdc 100644 --- a/scripts/lib/shield.php +++ b/scripts/lib/shield.php @@ -73,7 +73,7 @@ function shieldKey($keys, $device = null) 'back' => 'KEYCODE_BACK', 'home' => 'KEYCODE_HOME', 'pause' => 'KEYCODE_MEDIA_PLAY_PAUSE', - 'stop' => 'KEYCODE_MEDIA_STOP', + 'stop' => 'KEYCODE_HOME', 'space' => 'KEYCODE_SPACE', 'rewind' => 'KEYCODE_MEDIA_REWIND', 'fast-rewind' => 'KEYCODE_MEDIA_REWIND', @@ -285,12 +285,23 @@ function shieldIsAwake($device = null) return strpos($out, 'Display Power: state=ON') !== false; } +function shieldGetCurrentApp($device = null) +{ + $out = shieldCommand('shell', 'dumpsys window windows | grep -E \'mCurrentFocus|mFocusedApp|mResumedActivity\''); + foreach (shieldGetApps() as $name => $id) { + if (strpos($out, $id) !== false) { + return $name; + } + } + return null; +} + function _adb($command, $params = '', $device = null) { $c = _adbcmd($command, $params, $device); $output = `$c`; - echo $c . ' :: ' . $output . "\n"; + // echo $c . ' :: ' . $output . "\n"; return $output; } diff --git a/scripts/shield.php b/scripts/shield.php index a9b52c9..c33f624 100644 --- a/scripts/shield.php +++ b/scripts/shield.php @@ -12,6 +12,8 @@ if (isset($_GET['key'])) { } else if (isset($_GET['action'])) { if ($_GET['action'] == 'apps') { shieldListApps(); + } else if ($_GET['action'] == 'currentApp') { + shieldGetCurrentApp(); } } else if (isset($_GET['intents'])) { shieldFindIntents($_GET['intents']); -- 2.39.5