目的
Foltiaの予約番組リストは予約番組が重複していると色を付けて教えてくれるんですよね。 ただアニメやその他のキーワードで拾ってくる録画予約は週ごとに放映時間が変わったりしていつの間にか同時予約数が番組予約より多くなってることってありますよね。 チューナーの上限を超えると確か録画が全停止したような気がします。 最近うちのシステムでは起こってないので、もう覚えてないんですけどね。
番組予約上限はその他にも番組録画の最後と最初に付いてる1分ぐらいのマージンがあって、そのためFoltia側が重複してると認識していなくても切り替えの時期に重複していてチューナー上限を超えてしまうこともあります。 あと意外に解りにくいのが毎時50分にされてるePEGデーターの取り込みにチューナを使ってるので、その際に同時利用チャネル数が上限を超えているかもしれません(もしかしたら安全策がfotia側で取られているかもしれませんが・・・。)
これって毎日マニュアルで目で確認してたら結構大変な作業なんですよ。 なので私はこう言うのはAppleScriptに任せてます。
アップルスクリプト記述
私の場合、Main_Loop内に 06:55になったらチェックする様にしてます。 こんな感じの記載を加えてますかね。
if (do shell script "date +'%H:%M'") is "06:55" then JamCheck({}) of R
これでFoltiaRecStatus.scpt内に下の様なハンドラを入れて見ましょう。
--return jamcheck({})
on jamcheck(q)
set q to q & {erro:"", foltia:"foltia", web:"foltia.local", MaxChannel:4, pswd:""}
set Jufuku to ( (q's MaxChannel) + 1)
set L to load script file (((path to home folder from user domain) as string) & "Dropbox:Scripts:module:Log_forConsole_pub.scpt") as alias
set N to load script file (((path to home folder from user domain) as string) & "Dropbox:Scripts:module:HTML_pub.scpt") as alias
set foltiaURL to "curl --basic -u curl:" & q's pswd & " http://" & q's web & "/reservation/index.php?p="
set So to ""
repeat with i from 1 to 3 --3ページ目まで読み込んで処理します
set so1 to do shell script (foltiaURL & i as text)
set q1 to TrimByTag({source_:so1, key_:"<table>", key_end:"</table>"}) of N
if q1's found is false then return {erro:LogOnConsoleR({cmt:"Foltiaサーバー起動していない", open_:false}) of L} & q
set So to So & q1's oText
end repeat
set SoList to Makelist(So, "<tr class=") of N
set BSArray to {}
set GNDArray to {}
repeat with OneSo in SoList
set OneSo to OneSo's contents
set station to do shell script "echo " & quoted form of OneSo & "|tr \\\\r \\\\n|grep -e '<td class=\"station\">' |sed \"s/<[^>]*>//g\" ||true"
set title to do shell script "echo " & quoted form of OneSo & "|tr \\\\r \\\\n|grep -e '<td class=\"title\">' |sed \"s/<[^>]*>//g\" ||true"
set date_ to do shell script "echo " & quoted form of OneSo & "|tr \\\\r \\\\n|grep -e '<td class=\"date\">' |sed \"s/<[^>]*>//g\" ||true"
set time_ to do shell script "echo " & quoted form of OneSo & "|tr \\\\r \\\\n|grep -e '<td class=\"time\">' |sed \"s/<[^>]*>//g\" ||true"
set d_ to do shell script "echo " & quoted form of date_ & "|sed 's/([^)]*)//g'|sed 's/ $//g'||true"
if station is not "" and ( (offset of "BS" in station) > 0) then set BSArray to BSArray & {{station:station, title:title, StartT:(date d_) - 60, EndT:(date d_) - 60 * time_}}
if station is not "" and ( (offset of "BS" in station) = 0) then set GNDArray to GNDArray & {{station:station, title:title, StartT:(date d_) - 60, EndT:(date d_) - 60 * time_}}
end repeat
set comment to ""
--BS
set max_ to (count BSArray)
repeat with i from 1 to (max_)
set Res1 to (item i of BSArray)'s contents
set start1 to Res1's StartT
set Dup to {Res1}
repeat with ii from 1 to max_
if i is not ii then
set Res2 to (item ii of BSArray)'s contents
if (Res2's StartT ≤ start1) and (Res2's EndT > start1) then
end if
if (count Dup) ≥ Jufuku then
set comment to comment & "| [" & Res1's title & ":" & Res1's station & "~~" & ( (Res1's StartT) + 60) & "]は" & Jufuku & "番組以上と重複しています" & (ASCII character (13) )
log Dup
exit repeat
end if
end if
end repeat
end repeat
--地上波
set max_ to (count GNDArray)
repeat with i from 1 to (max_)
set Res1 to (item i of GNDArray)'s contents
set start1 to Res1's StartT
set Dup to {Res1}
repeat with ii from 1 to max_
if i is not ii then
set Res2 to (item ii of GNDArray)'s contents
if (Res2's StartT ≤ start1) and (Res2's EndT > start1) then
end if
if (count Dup) ≥ Jufuku then
set comment to comment & "| [" & Res1's title & ":" & Res1's station & "~~" & ( (Res1's StartT) + 60) & "]は" & Jufuku & "番組以上と重複しています" & (ASCII character (13) )
log Dup
exit repeat
end if
end if
end repeat
end repeat
if comment is "" then return true
return {erro:LogOnConsoleR({cmt:comment, open_:false}) of L} & q
--slack(comment & q's foltia) of L
--return comment
end jamcheck
このハンドラは実は記述が重複(地上波とBS)している部分があってあまり美しくないですし、メッセージがログに隠れちゃう事があって目に入りにくいかもしれませんね。
あと結構遅いです、最初のcurlのソース取り込みに時間がかかるようで、体感としては15秒ぐらい掛かる感じがします。 私の場合エラーがあればSlackにメッセージが来る様にしてますが、皆さんが一番良く使ってるメッセンジャーで利用されるのが良いでしょうね。 LINEとかでも良いんじゃ無いでしょうか? ちなみに私全くLINE使ってないんで・・・。
さらにrepeatの2重がけでインデントが多いです。
このハンドラは1年以上前に作った物で、当時からほとんど変更していないんですよ。 それぐらい安定していて修正する部分がないのと、ほとんど1週間とか2週間に一度ぐらい思い出した様に反応が戻ってくるんで、番組の編成期に一度番組予約をセットしちゃうとその後ほとんど動作してる感じが無いです。 まあ安全装置みたいな物なので、どちらかというと安全性重視になってます。
MaxChannelは最大の同時記録チャネル数に当たりますが、皆さんの環境に合わせて数を設定されると良いと思います。 記録の安定を望むならq's MaxChannelは3に設定しておくと良いかもしれませんね。 私の環境だとePEGの読み込みを録画予約が多い時間帯から外しているので、4で大丈夫そうです。