From f7768b4a68b2341b6366c287f6160eeac4308bdd Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Sat, 25 Apr 2020 12:05:51 +0200 Subject: [PATCH] Adding review feature and one sec tolerance --- convert_Videos.ps1 | 84 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/convert_Videos.ps1 b/convert_Videos.ps1 index af7afda..f21a741 100644 --- a/convert_Videos.ps1 +++ b/convert_Videos.ps1 @@ -4,6 +4,7 @@ #----------------------------------------------------------------------- # Edit the $videoPath variable to point to your video-files folder: +#$videoPath = 'M:\1_movies\_main.movies\' $videoPath = 'M:\2_serien\_main.series\' #----------------------------------------------------------------------- @@ -12,7 +13,7 @@ $profile = 'main10' $NVEncoder = "$PSScriptRoot\encoder\NVEncC64.exe" $fileTester = "$PSScriptRoot\mediainfo.exe" - +$reviewPlayer = "C:\Program Files\VideoLAN\VLC\vlc.exe" ############################################################################################################# # Testing and conversion preparations # @@ -29,7 +30,7 @@ $videos = Get-ChildItem -LiteralPath $videoPath -Name -Recurse -Include ('*.mp4' # Instantiating used variables: $videoID = 1 -$convertedVideos = 1 +$convertedVideos = 0 $notConvertedVideos = 0 $failedVideos = 0 # Square brackets are used as wildcards in Powershell. @@ -89,7 +90,7 @@ foreach($video in $videos) } else { $outputFile = $videoPath + $video.Insert(($video.Length - 4), '-HEVC') } - Write-Host "Analyzing video ($videoID of $count), starting convertion of number: $convertedVideos please wait.." -ForegroundColor Magenta + Write-Host "Analyzing video ($videoID of $count), starting convertion of number: $($convertedVideos + 1) please wait.." -ForegroundColor Magenta Write-Host "$video `nto:`n$outputFile" -ForegroundColor White Write-Host @@ -148,19 +149,31 @@ foreach($video in $videos) $Logfile = "$PSScriptRoot\logs\$logFolderName\successfully_converted.log" LogWrite "$outputFile" } else - { - # Delete corrupt File! - Write-Host "Conversion Failded! - Deleting new converted file.." -ForegroundColor Red - Write-Host - Write-Host "------------------------------------------------------------------------------------------------" - Remove-Item -LiteralPath $outputFile - $failedVideos = $failedVideos + 1 - $notConvertedVideos = $notConvertedVideos + 1 - $Logfile = "$PSScriptRoot\logs\$logFolderName\error_during_conversion.log" - LogWrite "$inputFile" + { + if (($StreamSize_new -eq $($StreamSize_old - 1)) -or ($($StreamSize_new - 1) -eq $StreamSize_old)) + { + # Delete old video File! + Write-Host "Conversion Done! - But streamsize is not exactly the same. - Please review!" + Write-Host + Write-Host "------------------------------------------------------------------------------------------------" + $review = $true + $convertedVideos = $convertedVideos + 1 + $Logfile = "$PSScriptRoot\logs\$logFolderName\review_needed.log" + LogWrite "$inputFile,$outputFile" + } else + { + # Delete corrupt File! + Write-Host "Conversion Failded! - Deleting new converted file.." -ForegroundColor Red + Write-Host + Write-Host "------------------------------------------------------------------------------------------------" + Remove-Item -LiteralPath $outputFile + $failedVideos = $failedVideos + 1 + $notConvertedVideos = $notConvertedVideos + 1 + $Logfile = "$PSScriptRoot\logs\$logFolderName\error_during_conversion.log" + LogWrite "$inputFile,$StreamSize_new,$StreamSize_old," + } } } - #Start-Sleep -Seconds 4 } else { # Alert if video doesn't need conversion: @@ -185,6 +198,49 @@ foreach($video in $videos) ############################################################################################################# # Evaluation part of the conversion script # ############################################################################################################# +if ($review) +{ + Write-Host "There are some files to review.. Starting reviewing first file." + Write-Host + $review_count = 1 + + foreach($review_pair in Get-Content -LiteralPath "$PSScriptRoot\logs\$logFolderName\review_needed.log") + { + $oldFile,$newFile = $review_pair.split(',') + Write-Host "Playing $review_count converted file: $newFile" + Write-Host + + # Starting VLC Player with the file to review + Start-Process $reviewPlayer -ArgumentList `"$newFile`" + Start-Sleep -Seconds 6 + + # Wait until player is closed. + $processID = (Get-Process "vlc").id + Wait-Process -Id $processID + + $msg = 'Do you want to keep the newly converted file and delete the old? (N for deleting NEW-file) [Y/N]' + do { + $response = Read-Host -Prompt $msg + } until (($response -eq 'n') -or ($response -eq 'y')) + + if ($response -eq 'y') + { + Write-Host "delete old file, keep newly converted.." + $to_delete = $oldFile + } else + { + Write-Host "delete newly converted, keep old file" + $to_delete = $newFile + $failedVideos = $failedVideos + 1 + $convertedVideos = $convertedVideos - 1 + } + Write-Host "DELETED: $to_delete" -ForegroundColor Red + #Remove-Item -LiteralPath $to_delete + Write-Host "------------------------------------------------------------------------------------------------" + Start-Sleep -Seconds 2 + } +} + Write-Host "Final calculations are in progress.." $folderSizeInGB2 = "{0:N2} GB" -f ((Get-ChildItem $videoPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB) if($notConvertedVideos -eq 0)