Skip to content

Commit

Permalink
Add tool Media Tools > Video: Fetch media info
Browse files Browse the repository at this point in the history
  • Loading branch information
AbyssMorgan committed May 2, 2023
1 parent 281eee2 commit bacae20
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 50 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
bin/*
AVE-PHP_v*.7z
AVE.ave-guard
3 changes: 1 addition & 2 deletions _get_package.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CD /D "%~dp0"
SET PATH=%PATH%;%CD%\bin\main;%CD%\bin\php;%CD%\bin\imagick
"%CD%\bin\php\php.exe" "%CD%\includes\main.php" --sort-settings
"%CD%\bin\php\php.exe" "%CD%\includes\main.php" --put-version
"%CD%\bin\php\php.exe" "%CD%\includes\main.php" --guard-generate
FOR /F "tokens=*" %%s IN ('TYPE "%CD%\version"') DO SET _VERSION=%%s
"%CD%\bin\main\7z.exe" a -mx9 -t7z "%CD%\AVE-PHP_v%_VERSION%.7z" "bin" "includes" "commands" "AVE-PHP.cmd" "AVE.ave-guard" "README.md" "LICENSE"
"%CD%\bin\main\7z.exe" a -mx9 -t7z "%CD%\AVE-PHP_v%_VERSION%.7z" "bin" "includes" "commands" "AVE-PHP.cmd" "README.md" "LICENSE"
PAUSE
44 changes: 4 additions & 40 deletions includes/AVE.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Services\IniFile;
use App\Services\Logs;
use App\Services\CommandLine;
use App\Services\GuardDriver;

use App\Tools\NamesGenerator;
use App\Tools\FileFunctions;
Expand All @@ -30,15 +29,14 @@ class AVE extends CommandLine {
public bool $open_log = false;

public string $app_name = "AVE";
public string $version = "1.5.1";
public string $version = "1.5.2";

private ?string $command;
private array $arguments;
private string $logo;
private string $tool_name;
private string $subtool_name;
private array $folders_state = [];
private string $guard_file;
private $tool;

private array $folders_to_scan = [
Expand Down Expand Up @@ -86,7 +84,6 @@ public function __construct(array $arguments){
$config_default = new IniFile($this->get_file_path("$this->path/includes/config/default.ini"), true);
$this->config = new IniFile($new_config, true);
$this->mkvmerge = new IniFile($this->get_file_path("$this->path/includes/config/mkvmerge.ini"), true);
$this->guard_file = $this->get_file_path("$this->path/AVE.ave-guard");

if($this->get_version_number($this->config->get('APP_VERSION','0.0.0')) < 10500){
$this->config->unset(['AVE_LOG_FOLDER','AVE_DATA_FOLDER','AVE_EXTENSIONS_AUDIO']);
Expand Down Expand Up @@ -146,16 +143,6 @@ public function __construct(array $arguments){

$dev = file_exists($this->get_file_path("$this->path/_get_package.cmd"));

if($version_changed && !$dev){
echo " Check for remove unused files...\r\n";
$validation = $this->validate(['damaged' => false, 'unknown' => true, 'missing' => false]);
foreach($validation as $error){
if($error['type'] == 'unknown'){
$this->unlink($this->get_file_path("$this->path/".$error['file']));
}
}
}

if($check_for_updates && !$dev){
$this->tool_update();
}
Expand All @@ -176,7 +163,7 @@ public function check_for_updates(string &$version) : bool {
return ($this->version != $response);
} else {
$error = curl_error($ch);
echo " Failed check for updates: $error\r\n";
echo " Failed check for updates: $error\r\n";
return false;
}
}
Expand All @@ -195,7 +182,7 @@ public function download_update(string $version) : void {
exec("START \"\" \"\"");
$this->abort = true;
} else {
echo " Failed download updates: $error\r\n";
echo " Failed download updates: $error\r\n";
}
}

Expand Down Expand Up @@ -235,15 +222,6 @@ public function execute() : void {
}
break;
}
case '--guard-generate': {
$guard = new GuardDriver($this->guard_file);
$cwd = getcwd();
chdir($this->path);
$guard->setFolders($this->folders_to_scan);
$guard->generate();
chdir($cwd);
break;
}
case '--sort-settings': {
$config = new IniFile("$this->path/includes/config/default.ini", true);
$config->save();
Expand All @@ -253,10 +231,6 @@ public function execute() : void {
file_put_contents("$this->path/version", $this->version);
break;
}
case '--guard-validate': {
echo print_r($this->validate(), true);
break;
}
case '--interactive': {
while(!$this->abort){
$this->abort = $this->select_tool();
Expand All @@ -271,16 +245,6 @@ public function execute() : void {
}
}

public function validate(array $flags = ['damaged' => true, 'unknown' => true, 'missing' => true]) : array {
$guard = new GuardDriver($this->guard_file);
$cwd = getcwd();
chdir($this->path);
$guard->setFolders($this->folders_to_scan);
$validation = $guard->validate($flags);
chdir($cwd);
return $validation;
}

public function set_tool(string $name) : void {
$this->tool_name = $name;
$this->subtool_name = '';
Expand Down Expand Up @@ -566,7 +530,7 @@ public function open_logs(bool $open_event = false, bool $init = true) : void {
$this->log_event->close();
$this->log_error->close();
$this->log_data->close();
if($open_event && file_exists($this->log_event->getPath())){
if($this->config->get('AVE_OPEN_LOG_EVENT') && $open_event && file_exists($this->log_event->getPath())){
$this->open_file($this->log_event->getPath());
}
if(file_exists($this->log_data->getPath())){
Expand Down
2 changes: 2 additions & 0 deletions includes/config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AVE_BACKUP_MAX_ALLOWED_PACKET=536870912
AVE_CHECK_FOR_UPDATES=true
AVE_CHECK_FOR_UPDATES_DAYS=7
AVE_COLOR="9F"
AVE_CSV_SEPARATOR=";"
AVE_DATA_FOLDER="%LOCALAPPDATA%\AVE\Data"
AVE_EXTENSIONS_AUDIO="mp3 ogg m4a wav aac opus m4a"
AVE_EXTENSIONS_PHOTO="bmp avif gd2 gd gif jpeg jpg png tga wbmp webp xbm xpm"
Expand All @@ -21,6 +22,7 @@ AVE_LOG_ERROR=true
AVE_LOG_EVENT=true
AVE_LOG_FOLDER="%LOCALAPPDATA%\AVE\Logs"
AVE_MAX_MEMORY_LIMIT="1G"
AVE_OPEN_LOG_EVENT=true
AVE_PART_SIZE=250
AVE_PREFIX_PHOTO="IMG"
AVE_PREFIX_VIDEO="VID"
Expand Down
25 changes: 21 additions & 4 deletions includes/services/MediaFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ public function getVideoDuration(string $path) : string {
}

public function getVideoThumbnail(string $path, string $output, int $w, int $r, int $c) : bool {
if(file_exists($path."_s.jpg")) return true;
$folder = pathinfo($path, PATHINFO_DIRNAME);
exec("mtn -w $w -r $r -c $c -P \"$path\" -O \"$output\" >nul 2>nul", $out);
return file_exists($output.DIRECTORY_SEPARATOR.pathinfo($path, PATHINFO_BASENAME)."_s.jpg");
$input_file = $output.DIRECTORY_SEPARATOR.pathinfo($path, PATHINFO_FILENAME)."_s.jpg";
$output_file = $output.DIRECTORY_SEPARATOR.pathinfo($path, PATHINFO_BASENAME).".webp";
if(file_exists($output_file)) return true;
if(!file_exists($input_file)){
exec("mtn -w $w -r $r -c $c -P \"$path\" -O \"$output\" >nul 2>nul", $out);
if(!file_exists($input_file)) return false;
}
$image = new Imagick();
$image->readImage($input_file);
$image->writeImage($output_file);
unlink($input_file);
return file_exists($output_file);
}

public function getMediaOrientation(int $width, int $height) : int {
Expand All @@ -99,6 +107,15 @@ public function getMediaOrientation(int $width, int $height) : int {
}
}

public function getMediaOrientationName(int $orientation) : string {
switch($orientation){
case MediaOrientation::MEDIA_ORIENTATION_HORIZONTAL: return 'Horizontal';
case MediaOrientation::MEDIA_ORIENTATION_VERTICAL: return 'Vertical';
case MediaOrientation::MEDIA_ORIENTATION_SQUARE: return 'Square';
}
return 'Unknown';
}

public function getMediaQuality(int $width, int $height) : string {
$v = max($width, $height);
if($v >= 30720){
Expand Down
4 changes: 4 additions & 0 deletions includes/tools/DirectoryFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function ToolDeleteEmptyDirs() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -116,6 +117,7 @@ public function ToolForceLoadIcon() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -168,6 +170,7 @@ public function ToolCountFiles() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -237,6 +240,7 @@ public function ToolCloneFolderStructure() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);

$this->ave->open_logs(true);
$this->ave->pause(" Operation done, press enter to back to menu");
Expand Down
3 changes: 3 additions & 0 deletions includes/tools/FileFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function ToolAntiDuplicates() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -167,6 +168,7 @@ public function ToolExtensionChange() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -271,6 +273,7 @@ public function ToolValidateCheckSum() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down
5 changes: 5 additions & 0 deletions includes/tools/MediaSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function ToolSortExtension() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -187,6 +188,7 @@ public function ToolSortMedia() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -241,6 +243,7 @@ public function ToolSortGifAnimated() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -330,6 +333,7 @@ public function ToolSortDate() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down Expand Up @@ -399,6 +403,7 @@ public function ToolSortImagesColor() : bool {
$this->ave->progress($items, $total);
$this->ave->set_progress($progress, $errors);
}
$this->ave->progress($items, $total);
unset($files);
$this->ave->set_folder_done($folder);
}
Expand Down
Loading

0 comments on commit bacae20

Please sign in to comment.