]> _ Git - tortuga-home.git/commitdiff
.
authorVincent <vincent@enhydra.fr>
Wed, 28 Apr 2021 20:32:52 +0000 (22:32 +0200)
committerVincent <vincent@enhydra.fr>
Wed, 28 Apr 2021 20:32:52 +0000 (22:32 +0200)
.idea/workspace.xml
scripts/lib/kodi.php
scripts/lib/tmdb.php
scripts/tmdb.php

index 083cfa206b4304d426d82bf89fb8bd26031e9883..0f6c90eb4244abade22d578a78f71df83d5e34c5 100644 (file)
@@ -3,8 +3,9 @@
   <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/global.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/global.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/lib/scenes.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/scenes.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/kodi.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/kodi.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/tmdb.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/tmdb.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="1618947923152" duration="2016000" />
       <workItem from="1619079821781" duration="1188000" />
       <workItem from="1619120393111" duration="2877000" />
-      <workItem from="1619342303709" duration="7803000" />
-    </task>
-    <task id="LOCAL-00425" summary=".">
-      <created>1609368280311</created>
-      <option name="number" value="00425" />
-      <option name="presentableId" value="LOCAL-00425" />
-      <option name="project" value="LOCAL" />
-      <updated>1609368280312</updated>
+      <workItem from="1619342303709" duration="8426000" />
+      <workItem from="1619637833459" duration="3836000" />
     </task>
     <task id="LOCAL-00426" summary=".">
       <created>1609368494151</created>
       <option name="project" value="LOCAL" />
       <updated>1619348281960</updated>
     </task>
-    <option name="localTasksCounter" value="474" />
+    <task id="LOCAL-00474" summary=".">
+      <created>1619544331948</created>
+      <option name="number" value="00474" />
+      <option name="presentableId" value="LOCAL-00474" />
+      <option name="project" value="LOCAL" />
+      <updated>1619544331948</updated>
+    </task>
+    <option name="localTasksCounter" value="475" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
index c490f9e813b98eaec1eccab2160a6758ee621b2e..25f0cb147873c98f806e464e85b24de038647e61 100644 (file)
@@ -1,12 +1,97 @@
 <?php
 $kodiClients = [];
 $kodiIP = ['salon' => '192.168.13.40', 'bureau' => '192.168.13.41', 'avion' => '192.168.13.5', 'cuisine' => '192.168.13.32'];
+$_tvshowallstatus = null;
+$_koditotmdb = null;
 
 function getKodiDBConnection()
 {
     return mysqli_connect('localhost', "kodi", "atacama", "MyVideos119");
 }
 
+function kodiGetAllKodiToTmdb($force=false)
+{
+    global $_koditotmdb;
+    if ($force || null === $_koditotmdb) {
+        try {
+            $_koditotmdb = connectRedis()->igbget('kodi.koditotmdb');
+        } catch (Exception $e) {
+            $_koditotmdb = false;
+        }
+
+        if ($force || $_koditotmdb === false) {
+            $_koditotmdb = [];
+            $con = getKodiDBConnection();
+            $result = mysqli_query($con, "SELECT media_id,value FROM uniqueid WHERE `type`='tmdb'");
+            while ($r = $result->fetch_assoc()) {
+                $_koditotmdb[$r['media_id']] = $r['value'];
+            }
+            connectRedis()->igbsetex('kodi.koditotmdb', 7200, $_koditotmdb);
+        }
+    }
+    return $_koditotmdb;
+}
+
+function kodiGetTVShowAllStatus($force=false)
+{
+    global $_tvshowallstatus;
+
+    if ($force || null === $_tvshowallstatus) {
+        try {
+            $_tvshowallstatus = connectRedis()->igbget('kodi.tvshow.status');
+        } catch (Exception $e) {
+            $_tvshowallstatus = false;
+        }
+
+        if ($force || $_tvshowallstatus === false) {
+            $con = getKodiDBConnection();
+            $result = mysqli_query($con, 'SELECT idShow,totalCount,watchedcount FROM tvshow_view');
+            if (!$result) {
+                print_r(mysqli_error_list($con));
+            }
+            $_tvshowallstatus = [];
+            while ($r = $result->fetch_assoc()) {
+                if ($r['watchedcount'] == null || !$r['watchedcount']) {
+                    $wc = 0;
+                } else {
+                    $wc = (int)$r['watchedcount'];
+                }
+
+                if ($r['totalCount'] == null || !$r['totalCount']) {
+                    $tc = 0;
+                } else {
+                    $tc = (int)$r['totalCount'];
+                }
+
+                if ($tc === 0) {
+                    $status = 3;
+                } else if ($wc >= $tc) {
+                    $status = 2;
+                } else if ($wc == 0) {
+                    $status = 1;
+                } else if ($wc < $tc) {
+                    $status = 0;
+                }
+                $_tvshowallstatus[kodiToTMDB($r['idShow'])] = $status;
+            }
+            connectRedis()->igbsetex('kodi.tvshow.status', 7200, $_tvshowallstatus);
+        }
+    }
+    return $_tvshowallstatus;
+}
+
+function kodiGetTVShowStatus($id)
+{
+    $allstatus = kodiGetTVShowAllStatus();
+    return $allstatus[$id] ?? 2;
+}
+
+function kodiToTMDB($id)
+{
+    $all = kodiGetAllKodiToTmdb();
+    return $all[$id] ?? null;
+}
+
 function kodiSyncPlayedStatus()
 {
     $con = getKodiDBConnection();
index 894d9d81fc706f41fb773a5b9b6893608df71896..2fcf0fa09595a3057dcef603c68d620f499a96e9 100644 (file)
@@ -182,7 +182,7 @@ class tvShowLibrary extends mediaLibrary
                 }
 
                 $data = $this->getTVShowByID($id);
-                $this->tvShows[] = ['type' => 'tvshow', 'dir' => $dir, 'data' => $data, 'id' => $id, 'mtime' => $mtime];
+                $this->tvShows[] = ['type' => 'tvshow', 'dir' => $dir, 'data' => $data, 'id' => $id, 'mtime' => $mtime, 'status' => $data['kodi_status']];
             }
         }
 
@@ -208,9 +208,8 @@ class tvShowLibrary extends mediaLibrary
             $client = getTmbdClient();
 
             try {
-                $tv = $client->getTvApi()->getTvshow($id, ['language' => 'fr-FR']);
-                connectRedis()->igbsetex('tmdb.tv.' . $id, 259200, $tv);
-                return $tv;
+                $res = $client->getTvApi()->getTvshow($id, ['language' => 'fr-FR']);
+                connectRedis()->igbsetex('tmdb.tv.' . $id, 259200, $res);
             } catch (Exception $e) {
                 echo $e->getMessage();
                 return null;
@@ -218,9 +217,16 @@ class tvShowLibrary extends mediaLibrary
 
         }
 
+        $res = $this->addKodiStatus($id, $res);
         return $res;
     }
 
+    public function addKodiStatus($id, $tv)
+    {
+        $tv['kodi_status'] = kodiGetTVShowStatus($id);
+        return $tv;
+    }
+
     protected function _sortTVByName($a, $b)
     {
         return mb_strcasecmp($a['data']['name'], $b['data']['name']);
@@ -232,9 +238,18 @@ class tvShowLibrary extends mediaLibrary
         $res = ['shortcuts' => [], 'subs' => []];
         $res['shortcuts']['size'] = 'poster';
         $res['shortcuts'][] = ['label' => 'Séries TV', 'type' => 'back'];
-        foreach ($this->tvShows as $tvShow) {
-            $this->shortcut($tvShow, '', $res);
+
+        $status = [0 => 'En cours', 1 => 'A voir', 2 => 'Vue', 3 => 'A venir'];
+        foreach ($status as $s => $label) {
+            $res['shortcuts'][] = ['label' => $label, 'type' => 'separator'];
+            foreach ($this->tvShows as $tvShow) {
+                if ($tvShow['status'] != $s) {
+                    continue;
+                }
+                $this->shortcut($tvShow, '', $res);
+            }
         }
+
         return $res;
     }
 
@@ -327,7 +342,13 @@ class tvShowLibrary extends mediaLibrary
 
     public function getRecents()
     {
-        $m = $this->tvShows;
+        $m = [];
+        foreach ($this->tvShows as $k => $show) {
+            if (!isset($show['status']) || $show['status'] >= 2) {
+                continue;
+            }
+            $m[$k] = $show;
+        }
         usort($m, function ($a, $b) {
             return $b['mtime'] - $a['mtime'];
         });
index 3e1aa34b37ee0145309971bfeb3f0432b9fcc1fa..f72824ce620aaa1067a69b72b1bc2b0c0d851e8c 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 ob_start();
 require_once 'import.php';
+kodiGetTVShowAllStatus(true);
+kodiGetAllKodiToTmdb(true);
 _getTVShows(true, false);
 _getMovies(true, false);
 _getMediaRecentAdded(true);