From 4a42ea2c6c05dd92faac7fc4bc66e0d8e802a30a Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 7 Dec 2020 09:44:42 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 41 +++++++++++------------------------- scripts/lib/kodi.php | 18 ++++++++++++---- scripts/lib/medialibrary.php | 30 +++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b13499f..ba0f796 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,16 +2,9 @@ - - - - - - - - - + + diff --git a/scripts/lib/kodi.php b/scripts/lib/kodi.php index 6d14bd2..894073c 100644 --- a/scripts/lib/kodi.php +++ b/scripts/lib/kodi.php @@ -38,10 +38,20 @@ function kodiSyncPlayedStatus() // Update kodi database foreach ($seen as $file => $s) { $file = str_replace('//', '/', $file); - if (!array_key_exists($file, $playCounts) || ($playCounts[$file] && $playCounts[$file] >= 0)) { - continue; + $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); } - $fileId = $files[$file]; - mysqli_query($con, 'UPDATE files SET playCount=1,lastPlayed=NOW() WHERE idFile=' . $fileId); + + } } \ No newline at end of file diff --git a/scripts/lib/medialibrary.php b/scripts/lib/medialibrary.php index d98f7ed..6523ef3 100644 --- a/scripts/lib/medialibrary.php +++ b/scripts/lib/medialibrary.php @@ -139,6 +139,24 @@ function mediaName($name, $context, $dir, $path) //// ////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 getTranscodedPath(SplFileInfo $item) +{ + $destext = $item->getExtension(); + if ($destext === 'avi') { + $destext = 'mkv'; + } + $normalized = $item->getRealPath(); + $normalized = str_replace('/volume1/Share', '', $normalized); + $normalized = str_replace('/nas', '', $normalized); + $normalized = str_replace('/mnt/smb/share', '', $normalized); + $normalized = str_replace('/mnt/sshfs/share', '', $normalized); + $normalized = 'c' . $normalized; + return '/mnt/smb/share/Videos/Transcoded/' . sha1($normalized) . '.' . $destext; + +} + function transcodeOneVideo() { if (getState('night') == '1' || getState('device_avion_awake') == '0') { @@ -157,8 +175,15 @@ function transcodeOneVideo() /** @var SplFileInfo $item */ $path = $item->getRealPath(); - $to = preg_replace('/\.' . $item->getExtension() . '$/', '.x264.' . $destext, $path); + $to = getTranscodedPath($item); + $oldto = preg_replace('/\.' . $item->getExtension() . '$/', '.x264.' . $destext, $path); + if (file_exists($oldto)) { + if (!file_exists($to) || filesize($oldto) > filesize($to)) { + rename($oldto, $to); + } + continue; + } if (file_exists($to) && filesize($to) != 0 && videosHaveSameDuration($path, $to)) { continue; @@ -239,6 +264,9 @@ function getVideosList($shuffle = false) if (!$f->isFile()) { continue; } + if (stristr($f->getPath(), 'Transcoded')) { + continue; + } if (!in_array($f->getExtension(), $videoExt)) { continue; } -- 2.39.5