]> _ Git - tortuga-home.git/commitdiff
.
authorVincent <vincent@enhydra.fr>
Wed, 4 Nov 2020 20:25:23 +0000 (21:25 +0100)
committerVincent <vincent@enhydra.fr>
Wed, 4 Nov 2020 20:25:23 +0000 (21:25 +0100)
.idea/workspace.xml
config/global.php
scripts/cron/cron.php
scripts/lib/harmony.php
scripts/lib/medialibrary.php
scripts/lib/off.php
scripts/lib/shield.php
scripts/lib/tmdb.php
scripts/transcode.php

index abcc2d1a86d14577ab3c66b8dc950b4c63f10437..4948ef82b1ef45b6ad2a6eb1a696fa91fa4af9c5 100644 (file)
@@ -3,9 +3,14 @@
   <component name="ChangeListManager">
     <list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/config/media.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/media.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/config/tv.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/tv.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/lib/cachemedia.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/cachemedia.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/config/global.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/global.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/cron/cron.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/cron/cron.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/harmony.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/harmony.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/medialibrary.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/medialibrary.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/off.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/off.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/shield.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/shield.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/tmdb.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/tmdb.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/transcode.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/transcode.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration default="true" type="ArquillianJUnit" factoryName="" nameIsGenerated="true">
-      <option name="arquillianRunConfiguration">
-        <value>
-          <option name="containerStateName" value="" />
-        </value>
-      </option>
-      <option name="TEST_OBJECT" value="class" />
-      <method v="2">
-        <option name="Make" enabled="true" />
-      </method>
-    </configuration>
     <configuration default="true" type="ArquillianTestNG" factoryName="">
       <option name="arquillianRunConfiguration">
         <value>
       <workItem from="1604042543878" duration="11137000" />
       <workItem from="1604152329376" duration="42646000" />
       <workItem from="1604347943058" duration="16133000" />
+      <workItem from="1604497757709" duration="6812000" />
     </task>
     <task id="LOCAL-00323" summary=".">
       <created>1591440466804</created>
       <screen x="0" y="0" width="1707" height="920" />
     </state>
     <state x="740" y="229" key="#com.jetbrains.php.refactoring.extractMethod.PhpExtractMethodDialog#function0/0.0.1707.920@0.0.1707.920" timestamp="1604146905948" />
-    <state x="198" y="0" width="737" height="502" key="CommitChangelistDialog2" timestamp="1604477469385">
+    <state x="198" y="0" width="737" height="502" key="CommitChangelistDialog2" timestamp="1604521334703">
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
     <state x="132" y="0" width="737" height="502" key="CommitChangelistDialog2/0.0.1707.920@0.0.1707.920" timestamp="1604307637401" />
     <state x="701" y="75" key="CommitChangelistDialog2/0.0.1920.1160@0.0.1920.1160" timestamp="1602171117745" />
-    <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1604477469385" />
+    <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1604521334703" />
     <state x="635" y="216" key="FileChooserDialogImpl" timestamp="1604227698339">
       <screen x="0" y="0" width="1707" height="920" />
     </state>
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
     <state x="295" y="0" width="1290" height="907" key="dock-window-1/0.0.2560.1040@0.0.2560.1040" timestamp="1603274697406" />
-    <state x="977" y="257" width="607" height="536" key="find.popup" timestamp="1604396363414">
+    <state x="977" y="257" width="607" height="536" key="find.popup" timestamp="1604520524183">
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
     <state x="651" y="227" width="550" height="534" key="find.popup/0.0.1707.920@0.0.1707.920" timestamp="1604301949692" />
-    <state x="977" y="257" width="607" height="536" key="find.popup/0.0.2560.1040@0.0.2560.1040" timestamp="1604396363414" />
+    <state x="977" y="257" width="607" height="536" key="find.popup/0.0.2560.1040@0.0.2560.1040" timestamp="1604520524183" />
+    <state x="1056" y="292" key="refactoring.ChangeSignatureDialog" timestamp="1604518096294">
+      <screen x="0" y="0" width="2560" height="1040" />
+    </state>
+    <state x="1056" y="292" key="refactoring.ChangeSignatureDialog/0.0.2560.1040@0.0.2560.1040" timestamp="1604518096294" />
     <state x="512" y="211" key="run.anything.popup" timestamp="1604146410464">
       <screen x="0" y="0" width="1707" height="920" />
     </state>
index 1db5c5697fc5f6183074d4cca7c091266044dddf..1b10dcd5c1500fb2e4114dc877632fc17876dc85 100644 (file)
@@ -49,7 +49,7 @@ $devices = [
     'entree' => ['id' => 'entree', 'host' => '192.168.13.64', 'user' => 'pi', 'password' => 'atacama'],
     'jarvis' => ['id' => 'jarvis', 'host' => '192.168.13.60', 'user' => 'jarvis', 'password' => 'atacama'],
     'chambre' => ['id' => 'chambre', 'host' => '192.168.13.65', 'user' => 'pi', 'password' => 'atacama'],
-    'salon' => ['id' => 'salon', 'host' => '192.168.13.66', 'user' => 'pi', 'password' => 'atacama'],
+    'salon' => ['id' => 'salon', 'host' => '192.168.13.66', 'shield' => '192.168.13.40', 'user' => 'pi', 'password' => 'atacama'],
     'bureau' => ['id' => 'bureau', 'host' => '192.168.13.67', 'user' => 'pi', 'password' => 'atacama'],
     'cuisine' => ['id' => 'cuisine', 'host' => '192.168.13.68', 'user' => 'pi', 'password' => 'atacama'],
     'bureausun' => ['id' => 'bureausun', 'host' => '192.168.13.70', 'user' => 'pi', 'password' => 'atacama'],
index 929e9d6a96455b79d0c4bde83daeb2b7d8a0eac6..f6f7d91fe906ab7a384c0ae3b1871b156937761f 100644 (file)
@@ -58,7 +58,13 @@ function cronXPlanet($cronmin)
 
 function cronShield($cronmin)
 {
-    shieldConnect(true);
+    global $devices;
+    foreach ($devices as $device) {
+        if (isset($device['shield'])) {
+            shieldConnect(true, $device['id']);
+        }
+    }
+    `curl 'http://192.168.13.60:9000/plugins/Extensions/settings/plugins/CastBridge/settings/basic.html?playerid=b8%3A27%3Aeb%3Af6%3A1d%3A30' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: fr-FR,en;q=0.5' --compressed -H 'Content-Type: application/x-www-form-urlencoded' -H 'Origin: http://192.168.13.60:9000' -H 'Connection: keep-alive' -H 'Referer: http://192.168.13.60:9000/plugins/Extensions/settings/plugins/CastBridge/settings/basic.html?playerid=b8%3A27%3Aeb%3Af6%3A1d%3A30' -H 'Cookie: Squeezebox-player=b8%3A27%3Aeb%3Af6%3A1d%3A30; Squeezebox-enableHiDPI=1; Squeezebox-expandPlayerControl=true; Squeezebox-expanded-MY_MUSIC=0; Squeezebox-expanded-RADIO=1; Squeezebox-expanded-PLUGIN_MY_APPS_MODULE_NAME=1; Squeezebox-expanded-FAVORITES=1; Squeezebox-expanded-PLUGINS=0; Squeezebox-playersettings=null; Squeezebox-advancedsettings=plugins/CastBridge/settings/basic.html%3F; Squeezebox-expanded-activePlugins=1; Squeezebox-expanded-inactivePlugins=1; Squeezebox-expanded-otherPlugins0=1' -H 'Upgrade-Insecure-Requests: 1' --data-raw 'saveSettings=1&useAJAX=0&page=PLUGIN_CASTBRIDGE&playerid=b8%3A27%3Aeb%3Af6%3A1d%3A30&player=b8%3A27%3Aeb%3Af6%3A1d%3A30&autorun=on&bin=squeeze2cast-armv6hf&opts=&debugs=&log_limit=-1&configfile=castbridge.xml&autosave=on&upnp_socket=%3F&xmlparams=1&prevseldevice=.common.&seldevice=.common.&codecs=aac%2Cogg%2Cops%2Cogf%2Cflc%2Calc%2Cwav%2Caif%2Cpcm%2Cmp3&sample_rate=96000&encode_mode=thru&encode_level=&encode_bitrate=&encode_rate=&encode_size=&server=%3F&enabled=1&remove_timeout=0&volume_on_play=1&media_volume=50&send_metadata=1&send_coverart=1&enabled.79a3f5f078d67e3b25a6b3dedc624e18=1'`;
 }
 
 function cronGuest($cronmin)
index aded60d7c086d8579d0134db96d98b853a9f4aff..bea7561a37ebcae8ca954d513b4aa19a44b36528 100644 (file)
@@ -43,6 +43,9 @@ function harmonyActivity($activity)
     if ($activity !== 'off' && $activity !== 'poweroff') {
         ecoMode('0');
     }
+    if ($activity === 'musique' || $activity === 'tv') {
+        shieldWakeup('salon');
+    }
     $res = harmonyRequest('activities/' . $activity, 'POST');
     if ($wait > 0) {
         sleep($wait);
index a890de002287261d1089cb16d9263419336af500..bbf169366e0b97cfc64a0627911531deff37c2a3 100644 (file)
@@ -3,17 +3,10 @@
 
 function getMediaContents($dir, $context, $seen = null)
 {
-    global $videoExt;
+    global $videoExt,$seen;
     $files = scandir($dir);
     $results = array();
 
-    if (null === $seen) {
-        $seen = connectRedis()->igbget('mediaseen');
-
-    }
-    if (!is_array($seen)) {
-        $seen = [];
-    }
 
     foreach ($files as $key => $value) {
         $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
@@ -25,8 +18,7 @@ function getMediaContents($dir, $context, $seen = null)
                     continue;
                 }
                 $normPath = normPath($path);
-                $x264path = getX264Version($normPath);
-                $results[] = array('path' => $x264path, 'srt' => hasSRT($normPath), 'seen' => isset($seen[$x264path]), 'dir' => false, 'name' => mediaName(implode(' ', $e), $context, false, $path));
+                $results[] = array('path' => $normPath, 'srt' => hasSRT($normPath), 'seen' => seen($normPath), 'dir' => false, 'name' => mediaName(implode(' ', $e), $context, false, $path));
             }
         } else if ($value != "." && $value != ".." && $value != '@eaDir') {
             $files = getMediaContents($path, $context, $seen);
@@ -37,7 +29,7 @@ function getMediaContents($dir, $context, $seen = null)
                 $results[] = $files[0];
             } else {
                 $normPath = normPath($path);
-                $results[] = array('path' => $normPath, 'seen' => isset($seen[$normPath]), 'dir' => true, 'id' => hash('sha256', $path), 'name' => mediaName($value, $context, true, $path), 'items' => $files);
+                $results[] = array('path' => $normPath, 'seen' => seen($normPath), 'dir' => true, 'id' => hash('sha256', $path), 'name' => mediaName($value, $context, true, $path), 'items' => $files);
             }
         }
     }
@@ -50,6 +42,29 @@ function getMediaContents($dir, $context, $seen = null)
     return $results;
 }
 
+function seen($path)
+{
+    global $seen;
+    if (!isset($seen) || null === $seen) {
+        $seen = connectRedis()->igbget('mediaseen');
+    }
+    if (!is_array($seen)) {
+        $seen = [];
+    }
+
+    $path = normPath($path);
+    if (isset($seen[$path])) {
+        return true;
+    }
+    $x264 = getX264Version($path, true);
+    if (isset($seen[$x264])) {
+        $seen[$path] = true;
+        connectRedis()->igbset('mediaseen', $seen);
+        return true;
+    }
+    return false;
+}
+
 function hasSRT($path)
 {
     $langs = ['fr', 'en'];
@@ -67,14 +82,14 @@ function hasSRT($path)
     return array_unique($res);
 }
 
-function getX264Version($path)
+function getX264Version($path, $forceReturn = false)
 {
     $e = explode('.', $path);
     $ext = array_pop($e);
     array_push($e, 'x264');
     array_push($e, $ext);
     $x264path = implode('.', $e);
-    if (file_exists($x264path)) {
+    if ($forceReturn || file_exists($x264path)) {
         return $x264path;
     }
     return $path;
@@ -115,57 +130,57 @@ function mediaName($name, $context, $dir, $path)
     }
     return $name;
 }
-
-// /volume1/@appstore/ffmpeg/bin/ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1  /volume1/Share/Videos/Series/Westworld/S01/E01.mkv
 //
-//ffmpeg -i /volume1/Share/Videos/Séries/Westworld/S01/E01.mkv -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 /volume1/Share/Videos/Séries/Westworld/S01/E01.x264.mkv
-
-function transcodeOneVideo()
-{
-    if (getState('night') == '1') {
-        return;
-    }
-
-    $list = getVideosList(true);
-
-    foreach ($list as $item) {
-
-        /** @var SplFileInfo $item */
-        $path = $item->getRealPath();
-        $to = preg_replace('/\.' . $item->getExtension() . '$/', '.x264.' . $item->getExtension(), $path);
-
-
-        if (file_exists($to) && filesize($to) != 0 && videosHaveSameDuration($path, $to)) {
-            continue;
-        } else {
-            echo $to . '/exists :' . file_exists($to) . '/size:' . filesize($to) . "\n\n";
-        }
-
-        set_time_limit(0);
-        ignore_user_abort(true);
-
-        if (!getNightMode()) {
-            wakeupPC('avion');
-            sleep(15);
-        }
-
-        $resize = getVideoHeight($path) > 1080 ? ' 1' : ' 0';
-        $cmd = 'C:\Scripts\convertvideo.bat "' . nasToAvion($item) . '" "' . nasToAvion($to) . '" ' . $item->getExtension() . ' ' . getVideoCodec($path) . $resize;
-        print_r(sshCommand($cmd, 'avion'));
-        return;
-    }
-    echo 'no file to transcode';
-}
-
-function videosHaveSameDuration($v1, $v2, $tolerance = 10)
-{
-    $d1 = getVideoDuration($v1);
-    $d2 = getVideoDuration($v2);
-    $diff = abs($d1 - $d2);
-    $res = $diff < $tolerance;
-    echo $v1 . '/' . $v2 . '/' . $d1 . '/' . $d2 . '/' . $diff . '/' . $res . "\n";
-    return $res;
-}
+//// /volume1/@appstore/ffmpeg/bin/ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1  /volume1/Share/Videos/Series/Westworld/S01/E01.mkv
+////
+////ffmpeg -i /volume1/Share/Videos/Séries/Westworld/S01/E01.mkv -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 /volume1/Share/Videos/Séries/Westworld/S01/E01.x264.mkv
+//
+//function transcodeOneVideo()
+//{
+//    if (getState('night') == '1') {
+//        return;
+//    }
+//
+//    $list = getVideosList(true);
+//
+//    foreach ($list as $item) {
+//
+//        /** @var SplFileInfo $item */
+//        $path = $item->getRealPath();
+//        $to = preg_replace('/\.' . $item->getExtension() . '$/', '.x264.' . $item->getExtension(), $path);
+//
+//
+//        if (file_exists($to) && filesize($to) != 0 && videosHaveSameDuration($path, $to)) {
+//            continue;
+//        } else {
+//            echo $to . '/exists :' . file_exists($to) . '/size:' . filesize($to) . "\n\n";
+//        }
+//
+//        set_time_limit(0);
+//        ignore_user_abort(true);
+//
+//        if (!getNightMode()) {
+//            wakeupPC('avion');
+//            sleep(15);
+//        }
+//
+//        $resize = getVideoHeight($path) > 1080 ? ' 1' : ' 0';
+//        $cmd = 'C:\Scripts\convertvideo.bat "' . nasToAvion($item) . '" "' . nasToAvion($to) . '" ' . $item->getExtension() . ' ' . getVideoCodec($path) . $resize;
+//        print_r(sshCommand($cmd, 'avion'));
+//        return;
+//    }
+//    echo 'no file to transcode';
+//}
+//
+//function videosHaveSameDuration($v1, $v2, $tolerance = 10)
+//{
+//    $d1 = getVideoDuration($v1);
+//    $d2 = getVideoDuration($v2);
+//    $diff = abs($d1 - $d2);
+//    $res = $diff < $tolerance;
+//    echo $v1 . '/' . $v2 . '/' . $d1 . '/' . $d2 . '/' . $diff . '/' . $res . "\n";
+//    return $res;
+//}
 
 function nasToAvion($path)
 {
@@ -199,82 +214,82 @@ class DirFilter extends RecursiveFilterIterator
     }
 }
 
-function getVideosList($shuffle = false)
-{
-    global $videoExt;
-    $res = array();
-    $dirit = new RecursiveDirectoryIterator('/nas/Videos');
-    $filtered = new DirFilter($dirit, ['@eaDir']);
-    $iterator = new RecursiveIteratorIterator($filtered, RecursiveIteratorIterator::CHILD_FIRST);
-
-    $toTranscode = ['hevc', 'vc1'];
-
-    foreach ($iterator as $f) {
-        /** @var $f SplFileInfo */
-        if (!$f->isFile()) {
-            continue;
-        }
-        if (!in_array($f->getExtension(), $videoExt)) {
-            continue;
-        }
-        $path = $f->getRealPath();
-
-        $codec = getVideoCodec($path);
-
-        if (!in_array($codec, $toTranscode)) {
-            continue;
-        }
-        if (preg_match('/[\&\[\]\|]/', $f->getFilename(), $matches)) {
-            continue;
-        }
-        $res[] = $f;
-    }
-    if ($shuffle) {
-        shuffle($res);
-    }
-    return $res;
-}
-
-function getVideoCodec($path)
-{
-    $cacheKey = 'codec_3_' . md5($path . '-' . filemtime($path) . '-' . filesize($path));
-    $res = getState($cacheKey, null);
-    if (null === $res) {
-        $codecfile = $path . '.vc';
-        if (file_exists($codecfile) && filesize($codecfile) > 0) {
-            $res = file_get_contents($codecfile);
-            unlink($codecfile);
-        } else if (stristr($path, '.x264.')) {
-            $res = 'h264';
-        } else {
-            $res = `ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$path"`;
-            $res = trim($res);
-        }
-        echo $path . '::' . $res . "\n";
-        setState($cacheKey, $res);
-    }
-    return $res;
-}
-
-function getVideoDuration($path)
-{
-    $cacheKey = 'duration_4_' . md5($path . '-' . filemtime($path) . '-' . filesize($path));
-    $res = getState($cacheKey, null);
-    if (null === $res) {
-        $res = `ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0"`;
-        setState($cacheKey, $res);
-    }
-    return (float)$res;
-}
-
-function getVideoHeight($path)
-{
-    $cacheKey = 'height_2_' . md5($path . '-' . filemtime($path));
-    $res = getState($cacheKey, null);
-    if (null === $res) {
-        $res = `ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=nw=1:nk=1 $path`;
-        $res = trim($res);
-        setState($cacheKey, $res);
-    }
-    return (int)$res;
-}
\ No newline at end of file
+//function getVideosList($shuffle = false)
+//{
+//    global $videoExt;
+//    $res = array();
+//    $dirit = new RecursiveDirectoryIterator('/nas/Videos');
+//    $filtered = new DirFilter($dirit, ['@eaDir']);
+//    $iterator = new RecursiveIteratorIterator($filtered, RecursiveIteratorIterator::CHILD_FIRST);
+//
+//    $toTranscode = ['hevc', 'vc1'];
+//
+//    foreach ($iterator as $f) {
+//        /** @var $f SplFileInfo */
+//        if (!$f->isFile()) {
+//            continue;
+//        }
+//        if (!in_array($f->getExtension(), $videoExt)) {
+//            continue;
+//        }
+//        $path = $f->getRealPath();
+//
+//        $codec = getVideoCodec($path);
+//
+//        if (!in_array($codec, $toTranscode)) {
+//            continue;
+//        }
+//        if (preg_match('/[\&\[\]\|]/', $f->getFilename(), $matches)) {
+//            continue;
+//        }
+//        $res[] = $f;
+//    }
+//    if ($shuffle) {
+//        shuffle($res);
+//    }
+//    return $res;
+//}
+//
+//function getVideoCodec($path)
+//{
+//    $cacheKey = 'codec_3_' . md5($path . '-' . filemtime($path) . '-' . filesize($path));
+//    $res = getState($cacheKey, null);
+//    if (null === $res) {
+//        $codecfile = $path . '.vc';
+//        if (file_exists($codecfile) && filesize($codecfile) > 0) {
+//            $res = file_get_contents($codecfile);
+//            unlink($codecfile);
+//        } else if (stristr($path, '.x264.')) {
+//            $res = 'h264';
+//        } else {
+//            $res = `ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$path"`;
+//            $res = trim($res);
+//        }
+//        echo $path . '::' . $res . "\n";
+//        setState($cacheKey, $res);
+//    }
+//    return $res;
+//}
+//
+//function getVideoDuration($path)
+//{
+//    $cacheKey = 'duration_4_' . md5($path . '-' . filemtime($path) . '-' . filesize($path));
+//    $res = getState($cacheKey, null);
+//    if (null === $res) {
+//        $res = `ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0"`;
+//        setState($cacheKey, $res);
+//    }
+//    return (float)$res;
+//}
+//
+//function getVideoHeight($path)
+//{
+//    $cacheKey = 'height_2_' . md5($path . '-' . filemtime($path));
+//    $res = getState($cacheKey, null);
+//    if (null === $res) {
+//        $res = `ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=nw=1:nk=1 $path`;
+//        $res = trim($res);
+//        setState($cacheKey, $res);
+//    }
+//    return (int)$res;
+//}
\ No newline at end of file
index 2e9f26800f97f3c2ad40c38130ff4507b50952bd..fa905ba13fb1b5598d1605e6c683c60e5f830905 100644 (file)
@@ -26,7 +26,9 @@ function commonOff($device)
 function offSalon()
 {
     stopHarmony();
-    execScene('salon/freebox/off');
+    shieldKillAll('salon');
+    shieldSleep('salon');
+    harmonyDeviceCommand('videoprojecteur-epson', 'power-off');
 }
 
 function offBureau()
index c771b32d96e85a119263efbcadf89b315110db56..59e35c19d325f1e2fd4aa8a5ce7abfafbc6db1a1 100644 (file)
@@ -1,20 +1,31 @@
 <?php
-define('SHIELD_HOST', '192.168.13.40');
 
 $shieldConnect = false;
 
-function shieldConnect($force = false)
+function shieldConnect($force = false, $device = null)
 {
     global $shieldConnect;
-    $lastConnect = getState('shield_lastconnect', null);
+    $d = getDevice($device);
+    $stateKey = 'shield_lastconnect_' . $d['id'];
+    $lastConnect = getState($stateKey, null);
     $limit = time() - 3600;
     if ($force || (!$shieldConnect && ($lastConnect === null || $lastConnect < $limit))) {
         $shieldConnect = true;
-        _adb('connect', SHIELD_HOST);
-        $lastConnect = getState('shield_lastconnect', time());
+        _adb('connect', $d['shield'], $device);
+        setState($stateKey, time());
     }
 }
 
+function shieldSleep($device = null)
+{
+    shieldKey('sleep', $device);
+}
+
+function shieldWakeup($device = null)
+{
+    shieldKey('wakeup', $device);
+}
+
 function shieldRunActivity($device = null)
 {
     $device = getDevice($device);
@@ -23,15 +34,15 @@ function shieldRunActivity($device = null)
     }
 }
 
-function shieldCommand($command, $params)
+function shieldCommand($command, $params, $device = null)
 {
-    shieldConnect();
-    _adb($command, $params);
+    shieldConnect(false, $device);
+    _adb($command, $params, $device);
 }
 
-function shieldText($text)
+function shieldText($text, $device = null)
 {
-    shieldCommand('shell', 'input text ' . $text);
+    shieldCommand('shell', 'input text ' . $text, $device);
 }
 
 function shieldKey($keys, $device = true)
@@ -81,13 +92,13 @@ function shieldKey($keys, $device = true)
         };
         $cmds[] = 'input keyevent ' . $key;
     }
-    shieldCommand('shell', ' "' . implode(' && ', $cmds) . '"');
+    shieldCommand('shell', ' "' . implode(' && ', $cmds) . '"', $device);
 }
 
 function shieldNetflix($id = null, $device = null)
 {
     shieldRunActivity($device);
-    shieldHome();
+    shieldHome($device);
     sleep(1);
 
     $url = 'http://www.netflix.com/';
@@ -97,16 +108,15 @@ function shieldNetflix($id = null, $device = null)
 
     setPlaying('netflix', $device);
     if ($id === 'home') {
-        shieldKill('netflix');
+        shieldKill('netflix', $device);
     }
-    //_adb('shell am start', ' -c android.intent.category.LEANBACK_LAUNCHER -a android.intent.action.VIEW -f 0x10808000 -e source 30 -d ' . $url . ' com.netflix.ninja/.MainActivity');
-    _adb('shell am start', ' -c android.intent.category.LEANBACK_LAUNCHER -a android.intent.action.VIEW -f 0x10808000 -e source 30 -d ' . $url . ' com.netflix.ninja/.MainActivity');
+    shieldCommand('shell am start', ' -c android.intent.category.LEANBACK_LAUNCHER -a android.intent.action.VIEW -f 0x10808000 -e source 30 -d ' . $url . ' com.netflix.ninja/.MainActivity', $device);
     if ($id === 'home') {
         sleep(6);
-        shieldKey(['ok', 'down']);
+        shieldKey(['ok', 'down'], $device);
     } else {
         sleep(1);
-        shieldKey(['ok']);
+        shieldKey(['ok'], $device);
     }
 }
 
@@ -116,34 +126,20 @@ function shieldRemoteCommand($cmd, $device = null)
     return true;
 }
 
-function shieldTVCommand($cmd)
+function shieldArte($device = null)
 {
-    $e = explode(':', $cmd);
-    if ($e[0] === 'netflix') {
-        shieldNetflix(isset($e[1]) ? $e[1] : null);
-    } else if ($e[0] === 'tv') {
-        if ($e[1] === 'replay') {
-            shieldTV(false, 'replay');
-        } else if ($e[1] === 'live') {
-            shieldTV($e[2], 'live');
-        }
-    }
-}
-
-function shieldArte()
-{
-    return shieldLaunchApp('tv.arte.plus7/.leanback.MainActivity');
+    shieldLaunchApp('tv.arte.plus7/.leanback.MainActivity', $device);
 }
 
-function shieldFranceTv()
+function shieldFranceTv($device = null)
 {
-    return shieldLaunchApp('fr.francetv.pluzz/fr.francetv.androidtv.main.MainActivity');
+    shieldLaunchApp('fr.francetv.pluzz/fr.francetv.androidtv.main.MainActivity', $device);
 }
 
-function shieldLaunchApp($activity)
+function shieldLaunchApp($activity, $device)
 {
-    shieldHome();
-    _adb('shell am start', '-n ' . $activity);
+    shieldHome($device);
+    shieldCommand('shell am start', '-n ' . $activity, $device);
 }
 
 function shieldMyCanal($channel = false, $type = 'live', $device = null)
@@ -151,9 +147,11 @@ function shieldMyCanal($channel = false, $type = 'live', $device = null)
     shieldRunActivity($device);
     if ($type === 'replay') {
         if ($channel === 'arte') {
-            return shieldArte();
+            shieldArte($device);
+            return;
         } else if ($channel === 'francetv') {
-            return shieldFranceTv();
+            shieldFranceTv($device);
+            return;
         }
         $url = 'https://www.canalplus.com/chaines/';
         if ($channel !== 'home') {
@@ -164,19 +162,16 @@ function shieldMyCanal($channel = false, $type = 'live', $device = null)
     }
 
     setPlaying('mycanal', $device);
-    shieldHome();
-    _adb('shell am start', '-a android.intent.action.VIEW -f 0x10808000 -d ' . $url . ' com.canal.android.canal/com.canal.app.common.legacy.DeepLinkActivity');
+    shieldHome($device);
+    shieldCommand('shell am start', '-a android.intent.action.VIEW -f 0x10808000 -d ' . $url . ' com.canal.android.canal/com.canal.app.common.legacy.DeepLinkActivity', $device);
 }
 
 function shieldKodi($file, $device = null)
 {
     shieldRunActivity($device);
-    shieldHome();
-    $device = getDevice($device);
-    if ($device === 'salon') {
-        harmonyActivity('tv');
-    }
-    _adb('shell am start', '-a android.intent.action.VIEW  -d \'"' . shieldNormalizeURL($file) . '"\' -n org.xbmc.kodi/.Splash');
+    shieldKillAll($device);
+    shieldHome($device);
+    shieldCommand('shell am start', '-a android.intent.action.VIEW  -d \'"' . shieldNormalizeURL($file) . '"\' -n org.xbmc.kodi/.Splash', $device);
 }
 
 function shieldNormalizeURL($input)
@@ -188,31 +183,28 @@ function shieldNormalizeURL($input)
     return $input;
 }
 
-function shieldVLC($file)
+function shieldVLC($file, $device = null)
 {
     shieldRunActivity($device);
-    shieldHome();
-    _adb('shell am start', '-a android.intent.action.VIEW  -d \'"' . shieldNormalizeURL($file) . '"\' -n org.videolan.vlc/.StartActivity');
+    shieldHome($device);
+    shieldCommand('shell am start', '-a android.intent.action.VIEW  -d \'"' . shieldNormalizeURL($file) . '"\' -n org.videolan.vlc/.StartActivity', $device);
 }
 
-function shieldListApps()
+function shieldListApps($device = null)
 {
-    shieldConnect();
-    _adb('shell pm list', 'packages -f');
+    shieldCommand('shell pm list', 'packages -f', $device);
 }
 
-function shieldFindIntents($app)
+function shieldFindIntents($app, $device)
 {
-    shieldConnect();
-
     $app = shieldGetAppId($app);
-    _adb('shell pm dump', $app);
-    _adb('shell pm dump', $app . ' | grep -A 1 "MAIN" | grep ' . $app . ' | awk \'{print $2}\' | grep ' . $app);
+    shieldCommand('shell pm dump', $app, $device);
+    shieldCommand('shell pm dump', $app . ' | grep -A 1 "MAIN" | grep ' . $app . ' | awk \'{print $2}\' | grep ' . $app, $device);
 }
 
 function shieldGetAppId($id = null)
 {
-    $apps = ['kodi' => 'org.xbmc.kodi', 'vlc' => 'org.videolan.vlc', 'netflix' => 'com.netflix.ninja', 'mycanal' => 'com.canal.android.canal', 'arte' => 'tv.arte.plus7', 'francetv' => 'fr.francetv.pluzz'];
+    $apps = shieldGetApps();
     if (null === $id) {
         return $apps;
     }
@@ -222,23 +214,49 @@ function shieldGetAppId($id = null)
     return $id;
 }
 
-function shieldHome()
+function shieldGetApps()
+{
+    return ['kodi' => 'org.xbmc.kodi',
+        'vlc' => 'org.videolan.vlc',
+        'netflix' => 'com.netflix.ninja',
+        'mycanal' => 'com.canal.android.canal',
+        'arte' => 'tv.arte.plus7',
+        'francetv' => 'fr.francetv.pluzz',
+        'gamecast' => 'com.nvidia.nvgamecast',
+        'teleloisirs' => 'fr.playsoft.teleloisirs',
+        'allocine' => 'com.allocine.androidapp',
+        'twitch' => 'tv.twitch.android.app',
+        'youtube' => 'com.google.android.youtube.tv',
+        'dailymotion' => 'com.dailymotion.dailymotion',
+        'vimeo' => 'com.vimeo.android.videoapp',
+        'plex' => 'com.plexapp.android',
+    ];
+}
+
+function shieldHome($device = null)
 {
-    $res = shieldKey('home');
+    shieldKey('home', $device);
     usleep(0.5 * 1000000);
-    return $res;
 }
 
-function shieldKill($app)
+function shieldKill($app, $device = null)
+{
+    shieldCommand('shell am', 'force-stop ' . shieldGetAppId($app), $device);
+}
+
+function shieldKillAll($device = null)
 {
-    shieldConnect();
-    _adb('shell am', 'force-stop ' . shieldGetAppId($app));
+    $apps = shieldGetApps();
+    foreach ($apps as $name => $app) {
+        shieldKill($name, $device);
+    }
 }
 
 
-function _adb($command, $params = '')
+function _adb($command, $params = '', $device = null)
 {
-    $c = 'adb ' . $command;
+    $device = getDevice($device);
+    $c = 'adb -s ' . $device['shield'] . ':5555 ' . $command;
     if ($params) {
         $c .= ' ' . $params;
     }
index 6c55c0d09b09f19e38487181322dc20a2fc9e18f..4681b62ae4a5cb28fc1b9c38618814356548a8f5 100644 (file)
@@ -289,15 +289,15 @@ class mediaLibrary
 
     protected function _path($p)
     {
-        $e = explode('.', $p);
-        $ext = array_pop($e);
-
-        array_push($e, 'x264');
-        array_push($e, $ext);
-        $x264 = implode('.', $e);
-        if (file_exists($x264)) {
-            $p = $x264;
-        }
+//        $e = explode('.', $p);
+//        $ext = array_pop($e);
+//
+//        array_push($e, 'x264');
+//        array_push($e, $ext);
+//        $x264 = implode('.', $e);
+//        if (file_exists($x264)) {
+//            $p = $x264;
+//        }
         return str_replace('/volume1/Share', '', $p);
     }
 
index 1f958edfa833d89ce6799615a9492a42f2288b2a..cb1d0af451d731ee2ac32b9d63be957f7f85ae18 100644 (file)
@@ -1,4 +1,4 @@
 <?php
 require_once 'import.php';
 
-transcodeOneVideo();
\ No newline at end of file
+//transcodeOneVideo();
\ No newline at end of file