-
Notifications
You must be signed in to change notification settings - Fork 19
/
get_missing_people.ps1
127 lines (112 loc) · 4.61 KB
/
get_missing_people.ps1
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
####################################################
# get_missing_people.ps1
# v1.3
# author: bullmoose20
#
# DESCRIPTION:
# In a powershell window this will go through all your meta*.log files created by Kometa to find all missing people posters.
# It will create 1 .cmd file per meta.log file and run it to download the images locally
#
# REQUIREMENTS:
# $metalog_location=is the path to the logs directory for Kometa
# Powershell security settings: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2
#
# PARAMETERS:
# -metalog_location (specify the logs folder location for Kometa)
#
# EXAMPLE:
# .\get_missing_people.ps1 -metalog_location \\NZWHS01\appdata\Kometa\logs
####################################################
param ($metalog_location)
#################################
# $metalog_location checks
#################################
if ($metalog_location -eq "" -or $null -eq $metalog_location) {
write-host "Logs location >$metalog_location< not found. Exiting now..." -ForegroundColor Red -BackgroundColor White
exit
}
if (-not(Test-Path -Path $metalog_location)) {
WriteToLogFile "Logs location >$metalog_location< not found. Exiting now..."
exit
}
#################################
# collect paths
#################################
$script_path = $PSScriptRoot
$scriptName = $MyInvocation.MyCommand.Name
$scriptLog = Join-Path $script_path -ChildPath "$scriptName.log"
$download_dir = Join-Path -Path $script_path -ChildPath "Downloads"
$step_del = Join-Path $metalog_location -ChildPath "*"
$outputfile = Join-Path $metalog_location -ChildPath "step1_download_"
$dds = Join-Path $download_dir ''
$mls = Join-Path $metalog_location ''
#################################
# WriteToLogFile function
#################################
Function WriteToLogFile ($message) {
Add-content $scriptLog -value ((Get-Date).ToString() + " ~ " + $message)
Write-Host ((Get-Date).ToString() + " ~ " + $message)
}
if (Test-Path $scriptLog) {
Remove-Item $scriptLog -Force | Out-Null
}
WriteToLogFile "#### START ####"
# Create dirs
New-Item -ItemType Directory -Force -Path $download_dir | Out-Null
# Remove step*.cmd from previous runs
Remove-Item $step_del -Include step*.cmd
# Gather all the meta* files
$inputFile = Get-ChildItem -Path $metalog_location -Name 'meta*' -File
ForEach ($item in $inputfile) {
WriteToLogFile "Found: $item"
}
# Define search pattern and newvalue
$theString = $null
$theOutput = $null
$find = $null
$item_path = $null
$pattern = $null
$newvalue = $null
$chcp = $null
$files_to_process = $null
$pattern = '\[\d\d\d\d-\d\d-\d\d .*\[.*\] *\| Detail: tmdb_person updated poster to \[URL\] (https.*)(\..*g) *\|\n.*\n.*\n.*Finished (.*) Collection'
$newvalue = "`n`n" + "powershell -command " + [char]34 + "Invoke-WebRequest " + '$1$2' + " -Outfile " + [char]92 + [char]34 + "$dds" + '$3$2' + [char]92 + [char]34 + "`n`n"
###################################################
# 1 - Find files in meta.log and download to download_dir
###################################################
ForEach ($item in $inputfile) {
$item_path = Join-Path $metalog_location -ChildPath "$item"
if (Test-Path -Path $item_path -PathType Leaf) {
$theOutput = $item.replace("$mls", "")
WriteToLogFile "Working on: $theOutput"
WriteToLogFile "Working on: $outputfile$theOutput.cmd"
Set-Content -Path $outputfile$theOutput.cmd -Value (((Get-Content $item_path -Raw) -replace "`r`n?", "`n") -replace $pattern, $newvalue)
$find = 'Invoke-WebRequest '
$theString = Get-Content $outputfile$theOutput.cmd | Select-String -Pattern $find -CaseSensitive -SimpleMatch
if ($theString -eq "" -or $null -eq $theString) {
Remove-Item $outputfile$theOutput.cmd
WriteToLogFile "0 items found..."
}
else {
$theString > tmp.txt
$theString = Get-Content tmp.txt
$theString = $theString.replace(' (Director).', '.')
$theString = $theString.replace(' (Producer).', '.')
$theString = $theString.replace(' (Writer).', '.')
$theString = $theString | Sort-Object -Unique
$chcp = "chcp 65001>nul"
Set-Content -Path $outputfile$theOutput.cmd -Value $chcp
Add-Content -Path $outputfile$theOutput.cmd -Value $theString
$files_to_process = $theString.Count - 1
WriteToLogFile "$files_to_process items found..."
Start-Process -FilePath $outputfile$theOutput.cmd -Wait
}
}
}
###################################################
# CLEANUP
###################################################
if (Test-Path tmp.txt) {
Remove-Item -Path tmp.txt -Force | Out-Null
}
WriteToLogFile "#### END ####"