]> _ Git - tortuga-home.git/commitdiff
.
authorVincent <vincent@enhydra.fr>
Sun, 15 Nov 2020 09:18:53 +0000 (10:18 +0100)
committerVincent <vincent@enhydra.fr>
Sun, 15 Nov 2020 09:18:53 +0000 (10:18 +0100)
.idea/workspace.xml
scripts/cron/cron.php
scripts/lib/medialibrary.php
scripts/transcode.php

index b8c2fad76980ef763b9c603a96c75adbcab44aef..2c183c0b8ab53a6fddc174d27df27fd75563e55a 100644 (file)
@@ -3,8 +3,8 @@
   <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/sdb.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/sdb.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/lib/medialibrary.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/medialibrary.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" />
       <workItem from="1605087787424" duration="33487000" />
       <workItem from="1605261347643" duration="1199000" />
       <workItem from="1605342171398" duration="4613000" />
-      <workItem from="1605355486465" duration="15137000" />
-    </task>
-    <task id="LOCAL-00345" summary=".">
-      <created>1602171129423</created>
-      <option name="number" value="00345" />
-      <option name="presentableId" value="LOCAL-00345" />
-      <option name="project" value="LOCAL" />
-      <updated>1602171129423</updated>
+      <workItem from="1605355486465" duration="15362000" />
     </task>
     <task id="LOCAL-00346" summary=".">
       <created>1602501505304</created>
       <option name="project" value="LOCAL" />
       <updated>1605428228628</updated>
     </task>
-    <option name="localTasksCounter" value="394" />
+    <task id="LOCAL-00394" summary=".">
+      <created>1605431702382</created>
+      <option name="number" value="00394" />
+      <option name="presentableId" value="LOCAL-00394" />
+      <option name="project" value="LOCAL" />
+      <updated>1605431702382</updated>
+    </task>
+    <option name="localTasksCounter" value="395" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
       <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="1605428224051">
+    <state x="198" y="0" width="737" height="502" key="CommitChangelistDialog2" timestamp="1605431699392">
       <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="1605086955514" />
     <state x="701" y="75" key="CommitChangelistDialog2/0.0.1920.1160@0.0.1920.1160" timestamp="1605188136787" />
-    <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1605428224051" />
+    <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1605431699392" />
     <state x="952" y="244" key="FileChooserDialogImpl" timestamp="1605104496549">
       <screen x="0" y="0" width="2560" height="1040" />
     </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="1605365749518">
+    <state x="977" y="257" width="607" height="536" key="find.popup" timestamp="1605431733312">
       <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="1605365749518" />
+    <state x="977" y="257" width="607" height="536" key="find.popup/0.0.2560.1040@0.0.2560.1040" timestamp="1605431733312" />
     <state x="1056" y="292" key="refactoring.ChangeSignatureDialog" timestamp="1604518096294">
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
index bfcd6e1b641c9c1f748fe5f21d4c0b60c1912626..bb8cc4fda4f17a4d28db847c00039d49d6858e0b 100644 (file)
@@ -90,8 +90,8 @@ function cronEcoMode($cronmin)
 
 function cronTranscode($cronmin)
 {
-    //_logSection('Transcode');
-    //httpRequest('https://salon.home.tortuga.enhydra.fr/scripts/transcode.php', 'get', [], null, 10, true);
+    _logSection('Transcode');
+    httpRequest('https://salon.home.tortuga.enhydra.fr/scripts/transcode.php', 'get', [], null, 10, true);
 }
 
 function _logSection($t)
index bbf169366e0b97cfc64a0627911531deff37c2a3..7b844ca611bac8e1ceb99a21168f0c773affc426 100644 (file)
@@ -3,7 +3,7 @@
 
 function getMediaContents($dir, $context, $seen = null)
 {
-    global $videoExt,$seen;
+    global $videoExt, $seen;
     $files = scandir($dir);
     $results = array();
 
@@ -18,7 +18,7 @@ function getMediaContents($dir, $context, $seen = null)
                     continue;
                 }
                 $normPath = normPath($path);
-                $results[] = array('path' => $normPath, 'srt' => hasSRT($normPath), 'seen' => seen($normPath), 'dir' => false, 'name' => mediaName(implode(' ', $e), $context, false, $path));
+                $results[] = array('path' => $normPath, 'x264path' => getX264Version($path, false), '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);
@@ -29,7 +29,7 @@ function getMediaContents($dir, $context, $seen = null)
                 $results[] = $files[0];
             } else {
                 $normPath = normPath($path);
-                $results[] = array('path' => $normPath, 'seen' => seen($normPath), 'dir' => true, 'id' => hash('sha256', $path), 'name' => mediaName($value, $context, true, $path), 'items' => $files);
+                $results[] = array('path' => $normPath, 'x264path' => getX264Version($path, false), 'seen' => seen($normPath), 'dir' => true, 'id' => hash('sha256', $path), 'name' => mediaName($value, $context, true, $path), 'items' => $files);
             }
         }
     }
@@ -130,57 +130,58 @@ 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;
-//}
+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)
 {
@@ -214,82 +215,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', 'xvid'];
+
+    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 cb1d0af451d731ee2ac32b9d63be957f7f85ae18..1f958edfa833d89ce6799615a9492a42f2288b2a 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