-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml_clean.ps1
53 lines (49 loc) · 1.98 KB
/
xml_clean.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
while ($true) {
$apitoken = "<PLEX_TOKEN>"
$dvrkey = "<DVR_KEY>"
$xmls = Get-ChildItem "/home/<USERNAME>/.xteve/data/*.xml"
function Set-Hashes{
$hashobjs = Get-FileHash -Algorithm SHA256 -Path $xmls
$hashobjs | ConvertTo-Json | Out-File "/home/<USERNAME>/.xteve/data/config.json"
Remove-Variable hashobjs
}
function Set-Xmls {
foreach ($xml in $xmls){
$cleanxml = Get-Content $xml | Where-Object { -not $_.Contains('src="https://tvguide2.cbsistatic.com/') }
$cleanxml | Out-File "$($xml.FullName)"
if (Test-Path "$xml.gz"){
Remove-Item "$xml.gz"
/usr/bin/gzip -k $xml.FullName
}
Remove-Variable cleanxml
}
}
if (Test-Path "/home/<USERNAME>/.xteve/data/config.json"){
$jsonobjs = ConvertFrom-Json (Get-Content -Raw "/home/<USERNAME>/.xteve/data/config.json")
$count = 0
foreach ($obj in $jsonobjs){
$livehash = (Get-FileHash -Algorithm SHA256 -Path $obj.Path).Hash
if ($livehash -ne $obj.Hash){
$count = $count+1
}
}
if ($count -ge 1){
Write-Host "$count JSON hash(es) does not match live file hash, cleaning XML files and building config.json"
Set-Xmls
Set-Hashes
Invoke-RestMethod -Method POST -Uri "http://127.0.0.1:32400/livetv/dvrs/$($dvrkey)/reloadGuide?X-Plex-Token=$($apitoken)"
}
else{
Write-Host "JSON hashes match live hashes, exiting script"
}
Remove-Variable count, livehash, jsonobjs
}
else{
Write-Host "No config file found. Cleaning XML files and creating config.json"
Set-Xmls
Set-Hashes
Invoke-RestMethod -Method POST -Uri "http://127.0.0.1:32400/livetv/dvrs/$($dvrkey)/reloadGuide?X-Plex-Token=$($apitoken)"
}
Start-Sleep -Seconds 5
[GC]::Collect()
}