-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_Cleanup.ps1
More file actions
66 lines (62 loc) · 2.13 KB
/
_Cleanup.ps1
File metadata and controls
66 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
param (
[string]$SearchFor = "(^.*S[\d]+E[\d]+).*",
[string]$ReplaceWith = "`$1.720p.x265.mkv",
[string]$FileExtension = "mkv",
[string]$RootFolder = "PATH\TO\YOUR\CLEANUP\FOLDER\"
)
$SeperatorString = "`n==============================================================================================================`n"
$RemuxErrorString = "Warnings/errors generated during remuxing, original file not deleted"
$NoRenamesString = "Nothing to rename"
$NoFilesString = "No files found."
$CompletedString = "Operation completed."
Write-Output $SeperatorString
Write-Output "Enumerating all $FileExtension files in $RootFolder"
Write-Output $SeperatorString
$Files = Get-ChildItem $RootFolder -Recurse -Include *.$FileExtension
if ($Files.Count -gt 0) {
$Files | ForEach-Object {
Write-Output "Cleaning titles in file $_."
Write-Output $SeperatorString
mkvpropedit "$_" -d title
mkvpropedit "$_" -e track:v1 -d name
mkvpropedit "$_" -e track:a1 -d name
mkvpropedit "$_" -e track:s1 -d name
Write-Output $SeperatorString
Write-Output "Title cleaning in file $_ is done."
Write-Output $SeperatorString
Write-Output "Searching for subtiltes in $_."
Write-Output $SeperatorString
$File = mkvmerge -i $_
$HasSub = $File[3].Contains("subtitles")
if ($HasSub) {
Write-Output "$_ has subtitles."
Write-Output $SeperatorString
$NewName = $_.FullName -replace $SearchFor, $ReplaceWith
mkvmerge -q -o "$NewName" -S $_
if ($LASTEXITCODE -eq 1) {
Write-Output $RemuxErrorString
}
else {
remove-Item $_
Write-Output "Successfully remuxed to $NewName, original file deleted"
}
}
else {
Write-Output "$_ has no subtitles, renaming file."
$NewName = $_.FullName -replace $SearchFor, $ReplaceWith
if ($_.FullName -ne $NewName) {
Rename-Item -Path $_.FullName -NewName $NewName
}
else {
Write-Output $SeperatorString
Write-Output $NoRenamesString
}
}
}
}
else {
Write-Output $NoFilesString
}
Write-Output $SeperatorString
Write-Output $CompletedString
Write-Output $SeperatorString