From f0b01694576d129d974ad5b5f6729889f52c5eff Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Sun, 16 Jul 2023 14:13:26 +0200 Subject: [PATCH] . --- .docker/config/httpd/httpd.conf | 2 +- .idea/workspace.xml | 28 ++- bin/updatedns.bat | 5 + scripts/lib/kodi.php | 326 ++++++++++++++++---------------- 4 files changed, 195 insertions(+), 166 deletions(-) create mode 100644 bin/updatedns.bat diff --git a/.docker/config/httpd/httpd.conf b/.docker/config/httpd/httpd.conf index d559470..b5e6a95 100644 --- a/.docker/config/httpd/httpd.conf +++ b/.docker/config/httpd/httpd.conf @@ -297,7 +297,7 @@ RemoteIPInternalProxy nginx-proxy - Require ip 127.0.0.0/8 192.168.0.0/16 172.0.0.0/8 172.27.13.0/24 + Require ip 127.0.0.0/8 192.168.0.0/16 172.0.0.0/8 172.27.13.0/24 130.180.213.67 diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a6e545c..bd93f09 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,10 @@ + + - + - + + + + @@ -1236,6 +1254,8 @@ + + 1641726946298 @@ -1580,7 +1600,7 @@ - diff --git a/bin/updatedns.bat b/bin/updatedns.bat new file mode 100644 index 0000000..186796b --- /dev/null +++ b/bin/updatedns.bat @@ -0,0 +1,5 @@ +@echo off +C:\tools\cygwin\bin\ssh.exe -tt root@192.168.13.6 '/usr/local/bin/updatedns' +C:\tools\cygwin\bin\ssh.exe -tt root@192.168.13.7 '/usr/local/bin/updatedns' +C:\tools\cygwin\bin\ssh.exe -tt root@192.168.13.64 '/usr/local/bin/updatedns' +C:\tools\cygwin\bin\ssh.exe -tt root@192.168.13.67 '/usr/local/bin/updatedns' \ No newline at end of file diff --git a/scripts/lib/kodi.php b/scripts/lib/kodi.php index 21c968c..ae2bcaa 100644 --- a/scripts/lib/kodi.php +++ b/scripts/lib/kodi.php @@ -4,182 +4,186 @@ $kodiIP = ['salon' => '192.168.13.40', 'bureau' => '192.168.13.41', 'avion' => ' $_tvshowallstatus = null; $_koditotmdb = null; -function getKodiDBConnection() -{ - return mysqli_connect('kodidb.home.tortuga.enhydra.fr', "root", "4xNkxCDAyWrp5VVthtgS", "MyVideos121",3307); +function getKodiDBConnection() { + return @mysqli_connect('192.168.13.7', "root", "4xNkxCDAyWrp5VVthtgS", "MyVideos121", 3307); } -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 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(); + if(!$con){ + return []; + } + $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 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(); + if(!$con){ + return []; + } + $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 kodiGetTVShowStatus($id) { + $allstatus = kodiGetTVShowAllStatus(); + return $allstatus[$id] ?? 2; } -function kodiToTMDB($id) -{ - $all = kodiGetAllKodiToTmdb(); - return $all[$id] ?? null; +function kodiToTMDB($id) { + $all = kodiGetAllKodiToTmdb(); + return $all[$id] ?? null; } -function kodiSyncPlayedStatus() -{ - $con = getKodiDBConnection(); - - $seen = connectRedis()->igbget('mediaseen'); - $seenChanged = false; - - $useen = []; - - foreach ($seen as $item => $true) { - $useen[_normalizeSeenFile($item)] = true; - } - - connectRedis()->igbset('mediaseen', $useen); - $seen = $useen; - - $result = mysqli_query($con, 'SELECT * FROM path'); - $paths = []; - while ($path = $result->fetch_assoc()) { - $p = _normalizeSeenFile($path['strPath']); - - $paths[$path['idPath']] = $p; - } - - $result = mysqli_query($con, 'SELECT * FROM files'); - $files = []; - $playCounts = []; - while ($file = $result->fetch_assoc()) { - if (!isset($paths[$file['idPath']])) { - continue; - } - $filename = $paths[$file['idPath']] . $file['strFilename']; - $files[$filename] = $file['idFile']; - $playCounts[$filename] = $file['playCount']; - if (null !== $file['playCount'] && !isset($seen[$filename])) { - $seen[$filename] = true; - $seenChanged = true; - } - } - - // Update seen if needed - if ($seenChanged) { - echo 'seen changed' . "
"; - connectRedis()->igbset('mediaseen', $seen); - } - // Update kodi database - foreach ($seen as $file => $s) { - $file = str_replace('//', '/', $file); - $e = explode('.', $file); - $ext = array_pop($e); - array_push($e, 'x264'); - array_push($e, $ext); - $x264 = implode('.', $e); - - foreach ([$file, $x264] as $f) { - if (!array_key_exists($f, $playCounts) || ($playCounts[$f] && $playCounts[$f] >= 0)) { - continue; - } - $fileId = $files[$f]; - mysqli_query($con, 'UPDATE files SET playCount=1,lastPlayed=NOW() WHERE idFile=' . $fileId); - } - } +function kodiSyncPlayedStatus() { + $con = getKodiDBConnection(); + if(!$con){ + return; + } + + $seen = connectRedis()->igbget('mediaseen'); + $seenChanged = false; + + $useen = []; + + foreach ($seen as $item => $true) { + $useen[_normalizeSeenFile($item)] = true; + } + + connectRedis()->igbset('mediaseen', $useen); + $seen = $useen; + + $result = mysqli_query($con, 'SELECT * FROM path'); + $paths = []; + while ($path = $result->fetch_assoc()) { + $p = _normalizeSeenFile($path['strPath']); + + $paths[$path['idPath']] = $p; + } + + $result = mysqli_query($con, 'SELECT * FROM files'); + $files = []; + $playCounts = []; + while ($file = $result->fetch_assoc()) { + if (!isset($paths[$file['idPath']])) { + continue; + } + $filename = $paths[$file['idPath']] . $file['strFilename']; + $files[$filename] = $file['idFile']; + $playCounts[$filename] = $file['playCount']; + if (null !== $file['playCount'] && !isset($seen[$filename])) { + $seen[$filename] = true; + $seenChanged = true; + } + } + + // Update seen if needed + if ($seenChanged) { + echo 'seen changed' . "
"; + connectRedis()->igbset('mediaseen', $seen); + } + // Update kodi database + foreach ($seen as $file => $s) { + $file = str_replace('//', '/', $file); + $e = explode('.', $file); + $ext = array_pop($e); + array_push($e, 'x264'); + array_push($e, $ext); + $x264 = implode('.', $e); + + foreach ([$file, $x264] as $f) { + if (!array_key_exists($f, $playCounts) || ($playCounts[$f] && $playCounts[$f] >= 0)) { + continue; + } + $fileId = $files[$f]; + mysqli_query($con, 'UPDATE files SET playCount=1,lastPlayed=NOW() WHERE idFile=' . $fileId); + } + } } -function _normalizeSeenFile($p) -{ - $p = str_replace('nfs://192.168.13.3/', '/', $p); - $p = str_replace(NAS_ROOT, '/volume1/Share/', $p); - $p = str_replace(NAS_PWD_ROOT, '/volume1/Share/', $p); - $p = str_replace('smb://Share:dcfyjbcyckwydtgufjx@192.168.13.4/Share//', '/volume1/Share/', $p); - $p = str_replace('smb://nas.home.tortuga.enhydra.fr/1.42.6-25556/', '/volume1/Share/', $p); - $p = str_replace('.x264.', '.', $p); - return $p; +function _normalizeSeenFile($p) { + $p = str_replace('nfs://192.168.13.3/', '/', $p); + $p = str_replace(NAS_ROOT, '/volume1/Share/', $p); + $p = str_replace(NAS_PWD_ROOT, '/volume1/Share/', $p); + $p = str_replace('smb://Share:dcfyjbcyckwydtgufjx@192.168.13.4/Share//', '/volume1/Share/', $p); + $p = str_replace('smb://nas.home.tortuga.enhydra.fr/1.42.6-25556/', '/volume1/Share/', $p); + $p = str_replace('.x264.', '.', $p); + return $p; } -function tmdbToKodiId($tmdbId, $type = 'tvshow') -{ - $result = mysqli_query(getKodiDBConnection(), 'SELECT `media_id` FROM `uniqueid` WHERE `value`="' . $tmdbId . '" AND `type`="tmdb"'); - while ($r = $result->fetch_assoc()) { - return $r['media_id']; - } +function tmdbToKodiId($tmdbId, $type = 'tvshow') { + $con=getKodiDBConnection(); + if(!$con){ + return false; + } + $result = mysqli_query($con, 'SELECT `media_id` FROM `uniqueid` WHERE `value`="' . $tmdbId . '" AND `type`="tmdb"'); + while ($r = $result->fetch_assoc()) { + return $r['media_id']; + } } -function kodiOpenTVShow($device, $tmdbId, $season = 1, $episode = 1) -{ - global $kodiIP; +function kodiOpenTVShow($device, $tmdbId, $season = 1, $episode = 1) { + global $kodiIP; - $ip = $kodiIP[$device]; - $json = '{"jsonrpc":"2.0","id":"1","method":"GUI.ActivateWindow","params":["videos",["videodb://tvshows/titles/' . tmdbToKodiId($tmdbId) . '/' . $season . '","return"]]}'; - `curl 'http://$ip:8754/jsonrpc' --data-raw '$json'`; + $ip = $kodiIP[$device]; + $json = '{"jsonrpc":"2.0","id":"1","method":"GUI.ActivateWindow","params":["videos",["videodb://tvshows/titles/' . tmdbToKodiId($tmdbId) . '/' . $season . '","return"]]}'; + `curl 'http://$ip:8754/jsonrpc' --data-raw '$json'`; } \ No newline at end of file -- 2.39.5