Created
July 10, 2018 13:13
-
-
Save AndroPlus-org/24415504b4d93fa56b27c36d0fb50858 to your computer and use it in GitHub Desktop.
Mirakurunのprograms.jsonとEPGStationのreserves.jsonの先頭が0で埋まっている時に削除して作り直させる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$mirak_url = "http://192.168.1.xxx:40772" | |
$epg_url = "http://192.168.1.xxx:8888" | |
Function Convert-FromUnixDate ($UnixDate) { | |
[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($UnixDate)) | |
} | |
<# | |
#MirakurunのAPIを確認し、チューナーが使用中でない状態になるまで待機する | |
Write-Output "Checking tuner status..." | |
$tuner_free = $FALSE | |
$tuner_url = "${mirak_url}/api/tuners" | |
do { | |
$response = Invoke-RestMethod -Method "Get" -Uri $tuner_url | |
if("$($response.isUsing)".Contains("True")){ | |
$tuner_free = $FALSE | |
Write-Output "Tuner status: Active..." | |
Write-Output "Waiting..." | |
Start-Sleep 10 | |
} else { | |
$tuner_free = $TRUE | |
Write-Output "Tuner status: Inactive." | |
} | |
} until ( $tuner_free ) | |
#> | |
#録画時間を確認し、30分以上先であれば削除しても問題ないと判断する | |
$rec_url = "${epg_url}/api/reserves" | |
$result = Invoke-RestMethod -Method "Get" -Uri $rec_url | |
$currentTime = Get-Date | |
$isSafe = $FALSE | |
foreach ($entry in $result.reserves.program.GetEnumerator()) { | |
#EPGStationのUNIX Timeはミリ秒を含んでいるので1000で割る | |
$startAt = Convert-FromUnixDate( $result.reserves.program[0].startAt / 1000 ) | |
$endAt = Convert-FromUnixDate( $result.reserves.program[0].endAt / 1000 ) | |
#現在の時間との比較をする | |
$startAtDuration = New-TimeSpan $currentTime $startAt | |
$endAtDuration = New-TimeSpan $currentTime $endAt | |
#30分以上先か確認 | |
if ( ( $startAtDuration.TotalMinutes -ge 30 ) -And ( $endAtDuration.TotalMinutes -ge 30 ) ) { | |
$isSafe = $TRUE | |
} | |
else { | |
$isSafe = $FALSE | |
} | |
} | |
#すべて問題なければ | |
if ( $isSafe ) { | |
Write-Output "Now checking json files..." | |
$programs = "C:\Users\XXX\AppData\Local\Mirakurun\programs.json" | |
$reserves = "C:\EPGStation\data\reserves.json" | |
$is_wipe_needed = $FALSE | |
$a = [System.IO.File]::ReadAllBytes("${programs}"); | |
$header += "{0:X2}" -f $a[0] | |
$header += "{0:X2}" -f $a[1] | |
$header += "{0:X2}" -f $a[2] | |
$header += "{0:X2}" -f $a[3] | |
$b = [System.IO.File]::ReadAllBytes("${reserves}"); | |
$headerb += "{0:X2}" -f $b[0] | |
$headerb += "{0:X2}" -f $b[1] | |
$headerb += "{0:X2}" -f $b[2] | |
$headerb += "{0:X2}" -f $b[3] | |
if ($header -eq "00000000") { | |
Write-Host "${programs}: ZAP! ZAP! ZAP!" | |
$is_wipe_needed = $TRUE | |
} | |
else { | |
Write-Host "${programs}: OK." | |
} | |
if ($headerb -eq "00000000") { | |
Write-Host "${reserves}: ZAP! ZAP! ZAP!" | |
$is_wipe_needed = $TRUE | |
} | |
else { | |
Write-Host "${reserves}: OK." | |
} | |
if ($is_wipe_needed) { | |
Remove-Item "${programs}" | |
Remove-Item "${reserves}" | |
} | |
} | |
else { | |
Write-Output "Now is not the time to check..." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment