From: Vincent Date: Wed, 28 Apr 2021 20:32:52 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=75f12d68fee8ec0be81f7d5bffccdc28b808efe2;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 083cfa2..0f6c90e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,9 @@ - - + + + diff --git a/scripts/lib/kodi.php b/scripts/lib/kodi.php index c490f9e..25f0cb1 100644 --- a/scripts/lib/kodi.php +++ b/scripts/lib/kodi.php @@ -1,12 +1,97 @@ '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(); diff --git a/scripts/lib/tmdb.php b/scripts/lib/tmdb.php index 894d9d8..2fcf0fa 100644 --- a/scripts/lib/tmdb.php +++ b/scripts/lib/tmdb.php @@ -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']; }); diff --git a/scripts/tmdb.php b/scripts/tmdb.php index 3e1aa34..f72824c 100644 --- a/scripts/tmdb.php +++ b/scripts/tmdb.php @@ -1,6 +1,8 @@