Foltia with AppleScript

Foltia animelockerのトラブルシューティング

B-CASカードのエラーの検出と現在のチューナの録画状況を確認

現在の録画状況の確認-2

前回のFoltiaRecStatus.scptに続きを書いてみましょう。 ここから先は、B-CASカードのエラー状況の確認(pcscdエラー)、チューナの状況確認(Recpt1)、ライブ視聴のチャネル数、録画チャネル数、録画状況の判断材料の取得となります。

foltialog.hatenablog.com

今までApplescriptの記載はAppleScriptHTMLさんのアプリで作成していたのですが、これだとアップルクリプト作成ボタンを押してもスクリプト作成出来ないんですね・・。 

AppleScriptHTML

もう今のOSに対応してないんでしょうね・・。

なんで素のスクリプトDropboxにも上げておくことにします。

www.dropbox.com

set q to {foltia:"foltia", pswd:"*******"}

return FoltiaRecStatus(q)

 

on FoltiaRecStatus(q)

     --戻り値はブランク

     set q to q & {erro:"", foltia:"foltia", WarmUpTime:20, LiveBootUpNum:2, PCSC_errorMax:40, bug:false, pswd:""}

     set q to q & {web:q's foltia & ".local"}

     set bug to q's bug

     --bugはバグ検証時に実行しない項目です。 falseが本番となります。

     set q0 to q

     

     set cmd to "curl --basic -u curl:" & q's pswd & " http://" & q's web & "/reservation/||true"

     set oText to do shell script cmd

     set N to load script file ( ( (path to home folder from user domain) as string) & "Dropbox:Scripts:module:HTML_pub.scpt") as alias

     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 q1 to TrimByTag({source_:oText, key_:"<div id=\"reservedTable\">", key_end:"<!-- /id=reserveTable/end -->"}) of N

     if q1's found is false then return {erro:LogOnConsoleR({cmt:"Foltiaサーバー起動していない", open_:false}) of L} & q

     

     

     log "時間変数を定義"

     set cTime to do shell script "date -v+" & q's WarmUpTime & "M +'%Y-%m-%d %H:%M'"

     --cTime: checkTime Warm Up 時間を想定し、現在より未来の時間を想定する、 sTime < cTimeとなればワームアップ開始

     set curTime to do shell script "date +'%Y-%m-%d %H:%M'"

     --curTime: 現在時間

     set eTime to do shell script "date -v+600M +'%Y-%m-%d %H:%M'" #デフォルト値

     set e3Time to eTime

     --eTime: Recording中の一番直近の終了時間  e3Timeはその3分前

     set s3Time to eTime #デフォルト値

     --s3TimeStanbyRecording (StByRec)の最小開始時間から3分前

     set sTime to eTime #デフォルト値

     --sTimeStanbyRecording (StByRec)の最小開始時間

     

     set tList to MakeList(q1's oText, "</tr>") of N

     if (count of tList) is 1 then return {erro:LogOnConsoleR({cmt:"</tr>が見つからない、パスしてMainフレームへ", open_:false}) of L} & q

     set L_NowRec to {}

     --L_NowRecは現在記録中の番組情報のリスト

     set L_StByRec to {}

     --L_StByRecは現時点からWarmUpTimeまでの間に開始される番組のリスト

     set L_OverRec to {}

     --L_OverReceTimeに記録している番組リストを選択する予定でしたが、eTimerepeat中に移動するので上手く取り出せてないと思います。 今は使う予定無しです

     repeat with aBangumi in tList

          set iBangumi to {} ## station, title_, subtitle_,date_,time_

          set aBangumi to aBangumi's contents

          set station to do shell script "echo " & quoted form of aBangumi & "|tr \\\\r \\\\n|grep '<td class=\"station\">'|sed -e 's/<[^>]*>//g'||true"

          if station is not "" then

               set title_ to do shell script "echo " & quoted form of aBangumi & "|tr \\\\r \\\\n|grep '<td class=\"title\">'|sed -e 's/<[^>]*>//g'||true"

               set subtitle_ to do shell script "echo " & quoted form of aBangumi & "|tr \\\\r \\\\n|grep '<td class=\"subtitle\">'|sed -e 's/<[^>]*>//g'||true"

               set start_ to do shell script "echo " & quoted form of aBangumi & "|tr \\\\r \\\\n|grep '<td class=\"date\">'|sed -e 's/<[^>]*>//g'|sed -e 's/([^)]*)//g'|sed -e 's/ $//g'|sed -e 's|/|-|g'||true"

               

               set time_ to do shell script "echo " & quoted form of aBangumi & "|tr \\\\r \\\\n|grep '<td class=\"time\">'|sed -e 's/<[^>]*>//g'||true"

               set end_ to do shell script "date -v+" & time_ & "M -j -f '%Y-%m-%d %H:%M' " & quoted form of start_ & " +'%Y-%m-%d %H:%M'"

               set bs to false

               if text 1 thru 2 of station is "BS" then set bs to true

               if cTime < start_ then exit repeat

               

               set iBangumi to {station:station, title_:title_, subtitle_:subtitle_, start_:start_, time_:time_, end_:end_, bs:bs}

               

               if curTimestart_ then

                    set L_NowRec to L_NowRec & {iBangumi}

                    if end_ < eTime then set eTime to end_

               else if (start_eTime) and (end_ > eTime) then

                    set L_OverRec to L_OverRec & {iBangumi}

                    set L_StByRec to L_StByRec & {iBangumi}

               else

                    set L_StByRec to L_StByRec & {iBangumi}

               end if

               

          end if

     end repeat

     set q0 to q0 & {NowRec:L_NowRec, StByRec:L_StByRec, OverRec:L_OverRec}

     

     set e3Time to do shell script "date -v-3M -j -f '%Y-%m-%d %H:%M' " & quoted form of eTime & " +'%Y-%m-%d %H:%M'"

     if (count of L_StByRec) > 0 then

          set sTime to (L_StByRec's item 1)'s start_

          set s3Time to do shell script "date -v-3M -j -f '%Y-%m-%d %H:%M' " & quoted form of sTime & " +'%Y-%m-%d %H:%M'"

     end if

     set q0 to q0 & {curTime:curTime, cTime:cTime, eTime:eTime, sTime:sTime, s3Time:s3Time, e3Time:e3Time}

     

     --return q0

     

     log "pcscdログを作成"

     set pcscd to SerchForOnMessage({andKey_:{"pcscd"}, orKey_:{".c:221:", ".c:177:"}, dur:-50, foltia:q's foltia})

     if pcscd is not "" then

          LogOnConsoleR({cmt:(ASCII character 13) & pcscd, open_:false}) of L

          if not bug then set q1 to LiveChannel2({OnOf:"AllOff", foltia:q's foltia}) of me

          do shell script "ssh -4 root@" & q's foltia & ".local pcscd -H"

          --このpcscd -Hはカードデバイスをもう一度読み込むコマンドらしいのですが、録画を中断せず実行できるので設定してます。 あまり有効なコマンドでは無いみたいです。 カットしてよいでしょう。

          LogOnConsoleR({cmt:"pcscdエラー発生のため Live録画を中断 pcscd -H", open_:false}) of L

     end if

     

     log "Recpt1ログ作成用"

     set recpt to do shell script "ssh -4 foltia@" & q's foltia & ".local ps -C  recpt1  k -pcpu|grep -e 'recpt1'|grep -e '\\--b25 '|grep -v '\\--EMM'||true"

     if recpt is not "" then LogOnConsoleR({cmt:(ASCII character 13) & recpt & (ASCII character 13), open_:false}) of L

     

     log "録画全般の条件確認"

     set recpt_Rec to do shell script "Echo " & quoted form of recpt & "|tr \\\\r \\\\n|grep -v '/tmp/recfifo-'||true"

     set recptsid to do shell script "Echo " & quoted form of recpt & "|tr \\\\r \\\\n|grep -v '/tmp/recfifo-'|sed -e 's/^.*--sid [^ ]* \\([0-9]*\\) .*/\\1/g'||true"

     repeat with OneRecpt in (every paragraph of recpt_Rec)

          set OneRecpt to OneRecpt's contents

          set Rstatus to RecptStringToTime(OneRecpt) of me

          if ( (Rstatus's ProcSec) + 59) ≤ ( (Rstatus's EstimatedSecond) ) and Rstatus's pid is not "" then

               --ps aux上のプログラム動作秒 procSecと、ファイル名+現在時刻とから予測される秒 EstimatedSecond の差が60秒以上ある場合 Recpt1が動作していない事を示すのでエラーを表示する。

               LogOnConsoleR({cmt:"pid=" & Rstatus's pid & " Time=" & Rstatus's EstimatedSecond & "はプロセス動作時間に違いがあり。録画停止している可能性があります", open_:false}) of L

               --Rstatus = {pid:"10892",EstimatedSecond:"600"}が必須

               log "下記で停止しているRecpt1動画を停止出来るはず"

               --if (Rstatus's ProcSec > 0) and not bug then QuitRecpt(Rstatus) of me

               --以前はプロセス時間と予測動画時間の差が大きいと該当するRecpt1を停止するハンドラを入れてましたが、最近あまりうまく動作しなくなってきたので外してます。

          else if Rstatus's pid is "" then

               LogOnConsoleR({cmt:"RecptStringToTime のデーター抽出に失敗 Recpt=" & OneRecpt, open_:false}) of L

          end if

     end repeat

     

     

     log "Recpt1BSの情報取得"

     

     set BSrecptsid to do shell script "Echo " & quoted form of recpt & "|tr \\\\r \\\\n|sed -e 's/^.*--sid [^ ]* \\([0-9]*\\) .*/\\1/g'|grep -v ' 187 '|awk '{ if ($0 >= 100) print $0 }'||true"

     set BSrecptsid_Live to do shell script "Echo " & quoted form of recpt & "|tr \\\\r \\\\n|grep -e '/tmp/recfifo-'|sed -e 's/^.*--sid [^ ]* \\([0-9]*\\) .*/\\1/g'|grep -v ' 187 '|awk '{ if ($0 >= 100) print $0 }'||true"

     

     set Rp_BSCT to (count of (every paragraph of BSrecptsid) )

     --* BScount= Rp_BSCT (recpt1 BS count total)

     set Rp_BSCL to (count of (every paragraph of BSrecptsid_Live) )

     --* BSLiveCount=Rp_BSCL  (recpt1 BS count Live)

     set Rp_BSCR to Rp_BSCT - Rp_BSCL

     --* Rp_BSCR  (recpt1 BS count recording)

     set Rp_AllCR to (count of (every paragraph of recptsid) )

     set q0 to q0 & {pcscd:pcscd, recpt:recpt, recpt_Rec:recpt_Rec, recptsid:recptsid, BSrecptsid:BSrecptsid, BSrecptsid_Live:BSrecptsid_Live, Rp_BSCT:Rp_BSCT, Rp_BSCL:Rp_BSCL, Rp_BSCR:Rp_BSCR, Rp_AllCR:Rp_AllCR}

     

     return q0

end FoltiaRecStatus

 

 

(*SerchForOnMessage

dur: duration は秒で記載、 プラスなら 現時点から何秒間か/var/log/messagesを監視して andKey_ リストに含まれるキーワードを含む項目と、orKey_リストに含まれるワードが含まれる行があれば その時点でエスケープしてString log_を返却する。 マイナスならば、現時点から-秒前までのログを監視するが、時間短縮のため分単位で監視する。

andKey_: リストに含まれるキーワード stringを含む項目を取り出す

orKey_: リストに含まれるキーワードのいずれかを含む項目をさらに抽出する

*)

on SerchForOnMessage(q)

     set q to q & {foltia:"foltia", dur:10, andKey_:{"foltia"}, orKey_:{}}

     set cmd to "|tr \\\\r \\\\n|grep "

     if q's dur > 0 then

          repeat with i from 0 to q's dur

               set cmd to cmd & " -e '" & (do shell script "date -v+" & i & "S +'%b %d %H:%M:%S '") & "'"

          end repeat

     else

          repeat with i from 0 to ( (q's dur) / -60) div 1

               set cmd to cmd & " -e '" & (do shell script "date -v-" & i & "M +'%b %d %H:%M:'") & "'"

          end repeat

     end if

     

     repeat with andKey in q's andKey_

          set cmd to cmd & "|grep -e " & quoted form of andKey

     end repeat

     

     if (q's orKey_ is not {}) then set cmd to cmd & "| grep "

     repeat with orKey in q's orKey_

          set cmd to cmd & " -e " & quoted form of orKey

     end repeat

     

     if q's dur > 0 then

          repeat q's dur times

               set log_ to do shell script "ssh -4 foltia@" & q's foltia & ".local cat /var/log/messages " & cmd & "||true"

               if (log_) is not "" then exit repeat

               delay 1

          end repeat

     else

          set log_ to do shell script "ssh -4 foltia@" & q's foltia & ".local cat /var/log/messages " & cmd & "||true"

     end if

     

     return log_

end SerchForOnMessage

 

 

(*

Safariを使って、Foltiaのライブ視聴を起動するハンドラ。

ハンドラSafariOneと closeSafariWinに依存している。

OnOfはスイッチで "on"なら自動的に LiveBootUpNumの数だけ 物理チャネルCID 128でチューナをアクティベートする

10秒だってもBufferにチャージがなければ いったんライブ視聴を全停止してもう一度同じ動作を行う。

その後30秒経過しても title foltia LIVE:Now buffering..が変わらなければ、いったん本体に戻すことにする。 

その後上位のハンドラ内で、B-CASカードのリセットを行い、それでも復帰しなければ、フォルティアサーバーを再起動させる。

OnOfAllOffなら全Live視聴停止 offと指定されていたら、 物理チャネルCIDのライブ視聴を1個停止させる。

BSのアンテナが無い状態ですと、このFoltiaRecStatus自体が不要かもしれません。 ドロップ対策は別の方法を考えた方が良いでしょうね。

*)

on LiveChannel2(q)

     set q to q & {SID:"", CID:"128", OnOf:"on", foltia:"foltia", web:"foltia.local", LiveBootUpNum:2, pswd:""}

     set bug to true

     

     set L to load script file ( ( (path to home folder from user domain) as string) & "Dropbox:Scripts:module:Log_ForConsole_pub.scpt") as alias

     

     closeSafariWin({key_:"foltia"}) of me

     

     if q's OnOf is "on" then

          set CID to q's CID

          repeat q's LiveBootUpNum times

               tell application "Safari" to set ct to SafariOne("http://" & q's web & "/live/buffering.php?sid=" & CID & "&q=3") of me

               delay 2

               set CID to CID + 1

          end repeat

          

          delay 10

          --Now buffering... (0/3)

          tell application "Safari" to set SaText to text of document 1

          set Buff to do shell script "Echo " & quoted form of SaText & "|tr \\\\r \\\\n|grep 'Now buffering'||true"

          if Buff is "Now buffering... (0/3)" then

               do shell script "curl --basic -u curl:" & q's pswd & " 'http://" & q's web & "/live/?cmd=STOPALL'||true"

               closeSafariWin({key_:"foltia"}) of me

               delay 1

               if bug then LogOnConsoleR({cmt:"バッファーチャージなし1回目、StopAllして再チャレンジ", open_:false}) of L

               --StopAllをしてもう一度Live起動する

               set CID to q's CID

               repeat q's LiveBootUpNum times

                    tell application "Safari" to set ct to SafariOne("http://" & q's web & "/live/buffering.php?sid=" & CID & "&q=3") of me

                    delay 2

                    set CID to CID + 1

               end repeat

               delay 10

          end if

          

          repeat 30 times

               delay 1

               tell application "Safari" to if name of ct is not "foltia LIVE:Now buffering..." then exit repeat

          end repeat

          tell application "Safari"

               if name of ct is "foltia LIVE:Now buffering..." then

                    closeSafariWin({key_:"foltia"}) of me

                    do shell script "curl --basic -u curl:" & q's pswd & " 'http://" & q's web & "/live/?cmd=STOPALL'||true"

                    return {erro:"Safariのバッファーがチャージされない"} & q

               end if

          end tell

          

          LogOnConsoleR({cmt:"BS CID = " & q's CID & " から " & q's LiveBootUpNum & "チャネルをライブ起動しました", open_:false}) of L

          return {erro:"BS CID = " & q's CID & " から " & q's LiveBootUpNum & "チャネルをライブ起動しました"} & q

     else if q's OnOf is "ALLoff" then

          do shell script "curl --basic -u curl:" & q's pswd & " 'http://" & q's web & "/live/?cmd=STOPALL'||true"

          return {erro:LogOnConsoleR({cmt:"ライブ視聴画面をSTOPALLしました", open_:false}) of L} & q

     else if q's OnOf is "off" then

          do shell script "curl --basic -u curl:" & q's pswd & " 'http://" & q's web & "/live/live_stop.php?m3u8=" & q's CID & "_440k'||true"

          return {erro:LogOnConsoleR({cmt:"ライブ視聴画面 CID=" & q's CID & "を停止しました", open_:false}) of L} & q

     else --不明な入力

          return {erro:"OnOF on off以外が入力"} & q

     end if

     

end LiveChannel2

 

(*

このプロセスは recpt1ctlを使って、 pidを指定して録画をきちんとした手順で停止させるものであるが、時々停止しないことがある。 

EstimatedSecondの計算が、MXの様に2番組入っていたりするとプロセス作動時間が倍で計算されるみたいで、それがバグの原因かも。 

途中で録画が途切れた番組なので思い切って EstimatedSecond 0を指定して停止させた方がよいのかもしれない。 

ただ現状比較的安定しているのでしたのハンドラは休眠させている。 使用が必要なら上位のハンドラのコメントアウトを外して実行できるようにするとよいだろう。

*)

on QuitRecpt(q)

     set q to q & {pid:"", EstimatedSecond:"", SID:"", CID:"", foltia:"foltia", web:"foltia.local"}

     if (q's pid is not "") and (q's EstimatedSecond is not "") then

          set cmd to "/home/foltia/perl/tool/recpt1ctl --pid " & q's pid & " --time " & q's EstimatedSecond

          do shell script "ssh -4 root@" & q's foltia & ".local " & cmd

          return {erro:"停止完了"} & q

     end if

     if q's SID is "" and q's CID is "" then return {erro:"SID,CIDの入力がない"} & q

     if q's SID is not "" then set q's CID to C_function(q) of me

     if q's CID is not "" then set q's SID to C_function(q) of me

     set recpt to do shell script "ssh -4 foltia@" & q's foltia & ".local ps -C  recpt1  k -pcpu|grep -e 'recpt1'|grep -e '\\--b25 '|grep ' " & q's SID & " '||true"

     if recpt is "" then return {erro:"録画無し"} & q

     

     set q0 to RecptStringToTime(recpt) of me

     

     set cmd to "/home/foltia/perl/tool/recpt1ctl --pid " & q0's pid & " --time " & q0's EstimatedSecond

     do shell script "ssh -4 root@" & q's foltia & ".local " & cmd

     return {erro:"停止完了"} & q0 & q

end QuitRecpt

 

(*

recpt1psによって得られるコメントの内容を区切って取り出すためのハンドラ。 QuitRecptを動作させるために作成。

今は録画が正常に行われているかどうかをチェックする(持続時間の整合性を確認するだけ)だけになっている

*)

on RecptStringToTime(recpt)

     set q0 to {pid:"", ProcSec:0, EstimatedSecond:0}

     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 recpt to do shell script "echo " & quoted form of recpt & "|sed 's/^ *//'"

     --pid34桁のプロセスだと前方に空白が入るので、はじめに行頭の空白を消しておきます。

     try

          set pid to do shell script "echo " & quoted form of recpt & "|sed 's/^\\([0-9]*\\) .*/\\1/'"

          set ProcTime to do shell script "echo " & quoted form of recpt & "|sed 's/^[0-9]* [^ ]  *[^ ]*  *\\([0-9:]*\\) .*/\\1/'"

          set ProcSec to (do shell script "date -j -f '%H:%M' " & quoted form of ProcTime & " +'%s'") - (do shell script "date -j -f '%H:%M' " & quoted form of "0:00" & " +'%s'")

          set ProcSec to ProcSec as integer

          set ResRecptDur to do shell script "echo " & quoted form of recpt & "|sed 's/^.*--sid [^ ]* [^ ]* \\([0-9]*\\) .*/\\1/'"

          set ResRecptDur to ResRecptDur as integer

          --set startFromFileName to do shell script "echo " & quoted form of recpt & "|sed 's|^.*/home/foltia/php/tv/.[0-9]*--\\([0-9]*-[0-9]*\\)-.*|\\1|'"

          set startFromFileName to do shell script "echo " & quoted form of recpt & "|sed 's|.*-\\([0-9]*-[0-9]*\\)-[0-9]*\\.m2t$|\\1|'"

          

          set unixTimeStart to do shell script "date -j -f '%Y%m%d-%H%M' " & quoted form of startFromFileName & " +'%s'"

          set unixTimeNow to do shell script "date +'%s'"

     on error

          --Recptファイルps auxの情報の切り出しに失敗している。 この部分がかなり不安定でループが停止するので、エラー時にログに残してメインループに戻る様にした。

          --LogOnConsoleR({cmt:"RecptStringToTime に失敗 recpt=" & recpt, open_:false}) of L

          return q0

     end try

     set EstimatedSecond to (unixTimeNow - unixTimeStart) as integer

     return {pid:pid, ProcSec:ProcSec, EstimatedSecond:EstimatedSecond}

     --必要なものだけを返すようにしました。

     return {pid:pid, ProcTime:ProcTime, ProcSec:ProcSec, ResRecptDur:ResRecptDur, startFromFileName:startFromFileName, unixTimeStart:unixTimeStart, unixTimeNow:unixTimeNow, EstimatedSecond:EstimatedSecond}

end RecptStringToTime

 

 

(*

チャネルの物理チャネルと、フォルティアのチャネルを対応させるためのハンドラ、 これは関東バージョンなので各地方でそれぞれ異なると思う。 

以前使っていたがもしかしたら現在使っていない可能性もあるが、将来の拡張性を考えて記載を残しておく

*)

on C_function(q)

     set q to q & {CID:"", SID:""}

     if q's CID is "" and q's SID is "" then return ""

     set Tbl to "\nS27|C1\nS26|C2\nS21|C3\nS25|C4\nS22|C5\nS24|C6\nS23|C7\nS18|C8\nS16|C19\nS30|C187\nS101|C9\nS102|C10\nS171|C15\nS161|C16\nS181|C17\nS151|C18\nS141|C71\nS211|C128\nS222|C129\nS103|C179"

     

     if q's CID is not "" then

          return do shell script "Echo " & quoted form of Tbl & "|tr \\\\r \\\\n| grep 'C" & q's CID & "$'|sed -e 's/^S//g'|sed -e 's/|C[0-9]*$//g'||true"

     else

          return do shell script "Echo " & quoted form of Tbl & "|tr \\\\r \\\\n| grep 'S" & q's SID & "'|sed -e 's/^[A-Z,0-9]*|C//g'||true"

     end if

end C_function

 

 

(*

Safariで特定のURLを開くプロセス。 ただSafariは起動状態でWindowが開いていないと、正常に動作しないこともあるので、このハンドラを作成した。

*)

on SafariOne(url_)

     tell application "Safari"

          activate

          repeat 10 times

               try

                    if every document is {} then make new document

                    exit repeat

               end try

               delay 0.1

          end repeat

          tell window 1 to set ct to (make new tab)

          tell window 1 to set current tab to last tab

          tell document 1 to set Name1 to name

          set URL of document 1 to (url_)

          tell document 1

               repeat 2000 times

                    if Name1 is not name then exit repeat

                    delay 0.1

               end repeat

          end tell

          

          if URL of document 1 is not url_ then

               delay 1

               set URL of document 1 to (url_)

          end if

          return ct

     end tell

     

end SafariOne

 

(*

Safariでタブを使っていると、目的のタブを閉じるのが難しかったりする。 

タブを閉じるとタブの番号も変わってしまうので、降順に一つづつチェックして閉じるようにした。

*)

 

on closeSafariWin(q)

     set q to q & {key_:""}

     if q's key_ is "" then return {erro:"key_ is empty"} & q

     tell application "Safari"

          repeat with win in (every window)

               tell (win's contents)

                    set num to count of (every tab)

                    set i to num

                    repeat num times

                         if (tab i)'s name contains q's key_ then close tab i

                         set i to i - 1

                    end repeat

               end tell

          end repeat

     end tell

end closeSafariWin

 

(*

B-CASカードリーダのリセット 

*)

on ReflesUSBCardReader(q) --★★完了

     set q to q & {Logging:true, foltia:"foltia", slack:true}

     set L to load script file ( ( (path to home folder from user domain) as string) & "Dropbox:Scripts:module:Log_ForConsole_pub.scpt") as alias

     do shell script "ssh -t -4 root@" & q's foltia & ".local service pcscd restart"

     

     if q's slack then

          LogOnConsole({cmt:"【注意!】Restart USB Card reader", open_:false}) of L

          -- slack("M-loop; USB Card reader を再起動しました。") of L

     else

          LogOnConsole({cmt:"【注】Restart USB Card readerー録画終了に伴う通常動作", open_:false}) of L

     end if

     return {}

end ReflesUSBCardReader

 

(*

Foltiaサーバーの再起動

*)

on P00_foltia_restart_single(q) --★★完了

     set q to q & {t_:"05:00", foltia:"foltia", JPVolume:"JP-file-style"}

     set L to load script file ( ( (path to home folder from user domain) as string) & "Dropbox:Scripts:module:Log_ForConsole_pub.scpt") as alias

     LogOnConsole({cmt:"【警告】Restart foltia", open_:false}) of L

     --slack("M-loop; 【警告】Restart foltia") of L

     try

          tell application "Finder" to eject disk q's JPVolume

     end try

     do shell script "ssh -t -4 root@" & q's foltia & ".local \"shutdown -r now\""

     

     return {status:"リスタート"} & q

end P00_foltia_restart_single

 

結果は

{foltia:"foltia", pswd:”*******”, erro:"", WarmUpTime:20, LiveBootUpNum:2, PCSC_errorMax:40, bug:false, web:"foltia.local", NowRec:{{station:"TOKYO MX", title_:"弱キャラ友崎くん 2nd STAGE", subtitle_:"選択肢の前で迷い続けても物語は進まない", start_:"2024-02-28 22:00", time_:"30", end_:"2024-02-28 22:30", bs:false}}, StByRec:{}, OverRec:{}, curTime:"2024-02-28 22:12", cTime:"2024-02-28 22:32", eTime:"2024-02-28 22:30", sTime:"2024-02-29 08:12", s3Time:"2024-02-29 08:12", e3Time:"2024-02-28 22:27", pcscd:"", recpt:"26052 ?        Dl     0:37 /home/foltia/perl/tool/recpt1 --b25 --sid 211 211 - /tmp/recfifo-128_440k

26108 ?        Dl     0:27 /home/foltia/perl/tool/recpt1 --b25 --sid 222 222 - /tmp/recfifo-129_440k

26847 ?        DNl    0:16 /home/foltia/perl/tool/recpt1 --b25 --sid hd 16 1844 /home/foltia/php/tv/6915-9-20240228-2200-16.m2t", recpt_Rec:"26847 ?        DNl    0:16 /home/foltia/perl/tool/recpt1 --b25 --sid hd 16 1844 /home/foltia/php/tv/6915-9-20240228-2200-16.m2t", recptsid:"16", BSrecptsid:"211

222", BSrecptsid_Live:"211

222", Rp_BSCT:2, Rp_BSCL:2, Rp_BSCR:0, Rp_AllCR:1}

 

こんな感じで帰って来ます。

ちなみにこのSCPTファイルのハンドラは最終的にM-loop_pubに移植してゆくわけですが、その前段階として LogOnConsole({cmt:""}) of L は動作したSCPTファイル名で拡張子.logのコンソールログファイルを、書類フォルダに作成していきます。 今回はエラーが発生していると FoltiaRecStatus_2.logファイルが出来ているはずです。 

今回は結構8個のサブルーティンハンドラが書かれていますが、その機能は直前のコメント行に記載してます。

この後に直近に録画無し、録画準備中、録画中を判断するif分岐が続くのですが、最後の4項目についてだけ説明しておきましょう。

Rp_BSCTは Recpt1チューナが働いている(Rp_)、BSチャネル(C)Total数の略でそれが2個動いています。

Rp_BSCLの最後のLはLiveのみ

Rp_BSCRの最後のRはRecording

Rp_AllCRは全てのRecordingしているチャネル数を示してます(BS+地上波)。

これらから現在レコード中であるか、それとも予約直前のスタンバイ状態か、それとも直近に全く予約が無いかを判断してゆく訳です。 そのあたりは次回追記して見ましょう。 このハンドラはこの後2回ハンドラを追記して終了となります。

またこのハンドラ内にLog_ForConsole_pub.scptを引用してコメントアウトされてる、slackというコールがあります。 これはメッセンジャーのスラックへアラームメッセージを飛ばすハンドラを私の本物のscriptファイルLog_ForConsole.scptに記載しているんですが、slackが用意したAPIを使ったり、そのほかにもTwitterやLINEなどもこういうtokenを使ったcurlベースのメッセンジャーへの投稿が用意されているはずです。 そういうユニットを自分で実装すると管理が楽になります。 是非自分で挑戦して下さい。

zenn.dev 私はこちらを参考にして設定しました。