Advertisement
Guest User

Untitled

a guest
May 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #CBR to #CBZ
  2. [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
  3. new-item ".\Fulloutput$([DateTime]::Now.ToString("yyyyMMdd-HHmmss")).txt"
  4. $fullOutput=(Get-ChildItem ".\" -filter "Fulloutput*").FullName
  5.  
  6. #if path is to a folder
  7. function FolderPath {
  8.     $fileList = Get-ChildItem -filter "*.cb*" -recurse "$comicPath"
  9.     foreach ($x in $fileList) {
  10.         write-host "sending $x to get fixed"
  11.         FixFileExtensions -filename ($x.FullName)
  12.         write-host "file fixed, sending another"
  13.     }
  14.     FolderPathUnRAR
  15. }
  16.  
  17. #unrar contents
  18. function FolderPathUnRAR {
  19.     $fileList = Get-ChildItem -filter "*.cbr" -recurse "$comicPath"      
  20.     foreach ($x in $fileList) {
  21.         $xdirectory=$x.Directory.FullName
  22.         $xfile=$x.FullName
  23.         $xdestinationroot=$x.FullName.Trim($x.PsChildName)
  24.         $xdestinationfolder="$xdestinationroot$($x.Basename)"
  25.         mkdir $xdestinationfolder
  26.        
  27.         Write-Output "newfilename (only CBR's): $x"
  28.         &$unrarPath e -y -v $xfile $xdestinationfolder 2>&1 | Tee-Object -Variable unrarOutput
  29.         $unrarOutput | ForEach-Object {
  30.             Write-output "$_`r`n" >>"$fullOutput"
  31.             if($_ -like "*is not RAR archive*" -or $_ -like "*checksum error") {
  32.                 "$($x.name) - $($x.FullName) has an error:  $_" | out-file  -append ".\cbr2cbzlog.txt"
  33.             }            
  34.         }
  35.        
  36.         $logparse = Get-Content ".\cbr2cbzlog.txt" | out-string          
  37.         if ($logparse -like "*$($x.BaseName)*") {
  38.             "Bad File, Skipping ZIP $($x.BaseName)`r`n" | out-file  -append ".\cbr2cbzlog.txt"
  39.             Remove-Item -force -Recurse $xdestinationfolder
  40.         }
  41.         else {
  42.             [IO.Compression.ZipFile]::CreateFromDirectory("$xdestinationfolder","$xdestinationfolder.cbz")
  43.             Remove-Item -force -recurse $xdestinationfolder
  44.             Remove-Item -force -recurse $xfile
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50.  
  51. <#function FileParse {
  52.  
  53. $filelist = Get-Content $comicPath
  54.  
  55.  
  56. }#>
  57.  
  58. #fix file extensions with Trid
  59. function FixFileExtensions  {
  60.     param($filename)    
  61.     write-output "recieved $filename, processing"
  62.     &$tridPath -ce "$filename" -d:$tridDef
  63.     Write-Output "Trid done did it's stuff"
  64.     return
  65. }
  66.  
  67.  
  68. #get and check unrar path
  69. [string]$unrarPath = $(Get-Command 'unrar').Definition
  70. if ( $unrarPath.Length -eq 0 ) {
  71.     Write-Error "Unable to access unrar at location '$unrarPath'."
  72.    
  73.     #$unrarPath="C:\unrar\unrar.exe"   ------ uncomment this line out and comment other line out if you want to set it for all run
  74.     $unrarPath=Read-Host -Prompt "Please enter path to Unrar"
  75.     if ([string]::IsNullOrEmpty($unrarPath) -or (Test-Path -LiteralPath $unrarPath) -ne $true) {
  76.         Write-Error "Unrar.exe path does not exist '$unrarPath'."
  77.     }
  78.     else {
  79.         Write-host "Path is good: $unrarPath"
  80.        
  81.     }
  82. }
  83. else {
  84.     write-host "unrar found, using path: '$unrarPath'"
  85. }
  86.  
  87.  
  88. if((get-childitem ".\" -filter "cbr2cbzlog*").exists){Remove-Item ".\cbr2cbzlog.txt"}
  89. #get and check path to trid
  90. #$tridpath="Z:\Comics\cbr2cbz\app\trid.exe"    ---- uncomment this line out and comment other line out if you want to set it for all run
  91. $tridpath=Read-Host -Prompt "Please enter path to trid application file"
  92. if([string]::IsNullOrEmpty($tridPath) -or (Test-Path -LiteralPath $tridPath) -ne $true -or $tridPath -notlike "*trid*") {
  93.     Write-Error "Trid path not good '$tridPath'."
  94.     exit
  95. }
  96. else {
  97.     Write-host "Path is good: $tridPath"
  98. }
  99.  
  100. #Get and check path to trid def file
  101. #$tridDef="Z:\Comics\cbr2cbz\app\cbx.trd"    ---- uncomment this line out and comment other line out if you want to set it for all run
  102. $tridDef=Read-Host -Prompt "Please enter path to trid definition file (.trd)"
  103. if ([string]::IsNullOrEmpty($tridDef) -or (Test-Path -LiteralPath $tridDef) -ne $true -or $tridDef -notlike "*.trd") {
  104.     Write-Error "TridDefinition path not good ya dingus '$tridDef'."
  105.     exit
  106. }
  107. else {
  108.     Write-host "Path is good: $tridDef"
  109. }
  110.  
  111.  
  112. #$comicPath="c:\users\alex\desktop\cbr2cbz" ---- uncomment this line out and comment other line out if you want to set it for all run
  113. $comicPath=Read-Host "Please enter path to comics"
  114.     if([string]::IsNullOrEmpty($comicPath) -or (Test-Path -LiteralPath $comicPath) -ne $true) {
  115.  
  116.         Write-error "Path not valid"
  117.         exit
  118.        
  119.     }
  120.     FolderPath
  121.  
  122.  
  123. <#
  124.     File parse to be implemented TO BE implemented
  125.  
  126.     if ((get-item $comicPath) -is [System.IO.DirectoryInfo]) {
  127.         FolderPath
  128.     }
  129.     if ((get-item $comicPath) -isnot [System.IO.DirectoryInfo]) {
  130.         FileParse
  131.     }
  132.  
  133.  
  134. #>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement