Advertisement
Guest User

Untitled

a guest
May 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #CBR to #CBZ
  2.  
  3.  
  4. #getfile list from user (determine if it's a folder or a text file)
  5. function GetFileList {
  6.     $comicPath="c:\users\alex\desktop\cbr2cbz\"
  7.     #$comicPath=Read-Host "Please enter path to comics, or txt file with comics (include trailing directory markers)"
  8.     if ([string]::IsNullOrEmpty($comicPath) -or (Test-Path -LiteralPath $comicPath) -ne $true) {
  9.  
  10.     Write-host "Path not valid, please try again"
  11.     GetFileList
  12.     }
  13.     else {
  14.         if ((get-item $comicPath) -is [System.IO.DirectoryInfo]) {
  15.             FolderPath
  16.         }
  17.         if ((get-item $comicPath) -isnot [System.IO.DirectoryInfo]) {
  18.             FilePath
  19.         }
  20.     }
  21. }
  22.  
  23.  
  24.  
  25.  
  26. #if path is to a folder
  27. function FolderPath {
  28.     $fileList = Get-ChildItem -filter "*.cb*" -recurse "$comicPath"
  29.     foreach ($x in $fileList) {
  30.         write-host "sending $x to get fixed"
  31.         FixFileExtensions -filename ($x.FullName)
  32.         write-host "file fixed, sending another"
  33.     }
  34.     FolderPathUnRAR
  35. }
  36.  
  37. #unrar contents
  38. function FolderPathUnRAR {
  39.     $fileList = Get-ChildItem -filter "*.cbr" -recurse "$comicPath"      
  40.     foreach ($x in $fileList) {
  41.         cd $comicpath
  42.         mkdir $x.BaseName
  43.         Write-Output "newfilename (only CBR's): $x"
  44.         &$unrarPath e -v ($x).FullName ($x).basename 2>&1 | Tee-Object -Variable unrarOutput
  45.         $unrarOutput | ForEach-Object {
  46.             if($_ -like "*is not RAR archive*" -or $_ -like "*checksum error") {
  47.                 "$($x.FullName) has an error:  $_" | out-file  -append ".\test.txt"
  48.             }
  49.         }    
  50.     }
  51. }
  52.  
  53.  
  54.  
  55. function FilePath {
  56. }
  57.  
  58. #fix file extensions with Trid
  59. function FixFileExtensions  {
  60.     param($filename)    
  61.     write-output "recieved $filename, processing"
  62.     &$tridPath -v -ce "$filename" -d:$tridDef
  63.     Write-Output "Trid done did it's stuff"
  64.     return
  65.    
  66. }
  67.  
  68.  
  69. #get and check unrar path
  70. $unrarPath = $(Get-Command 'unrar').Definition
  71. if ( $unrarPath.Length -eq 0 ) {
  72.     Write-Error "Unable to access unrar at location '$unrarPath'."
  73.    
  74.     $unrarPath="C:\unrar\unrar.exe"
  75.     #$unrarPath=Read-Host -Prompt "Please enter path to Unrar"
  76.     if ([string]::IsNullOrEmpty($unrarPath) -or (Test-Path -LiteralPath $unrarPath) -ne $true) {
  77.         Write-Error "Unrar.exe path does not exist '$unrarPath'."
  78.     }
  79.     else {
  80.         Write-host "Path is good: $unrarPath"
  81.     }
  82. }
  83. else {
  84.     write-host "unrar found, using path: '$unrarPath'"
  85. }
  86.  
  87. #get and check path to trid
  88. $tridpath="Z:\Comics\cbr2cbz\app\trid.exe"
  89. #$tridpath=Read-Host -Prompt "Please enter path to trid"
  90. if ([string]::IsNullOrEmpty($tridPath) -or (Test-Path -LiteralPath $tridPath) -ne $true) {
  91.     Write-Error "Trid path does not exist '$tridPath'."
  92. }
  93. else {
  94.     Write-host "Path is good: $tridPath"
  95. }
  96.  
  97. #Get and check path to trid def file
  98. $tridDef="Z:\Comics\cbr2cbz\app\cbx.trd"
  99. #$tridDef=Read-Host -Prompt "Please enter path to trid definition file"
  100. if ([string]::IsNullOrEmpty($tridDef) -or (Test-Path -LiteralPath $tridDef) -ne $true -or $tridDef -notlike "*.trd") {
  101.     Write-Error "TridDefinition path does not exist '$tridDef'."
  102. }
  103. else {
  104.     Write-host "Path is good: $tridDef"
  105. }
  106. GetFileList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement