iEPGのファイルから各種情報を取り出してみるテスト v4

iEPGのファイルから、各種情報を取り出してm2TVで録画予約するための文字列を作成するAppleScriptです。

iEPGファイルをparseして、属性ラベルとデータのペアリストにして、さらにペアリストからレコードを作成。レコードにするとデータの扱いが楽になるので、取り出してm2TVが理解できそうな文字列に変換してみました。

テレビ局の情報がiEPGに記載されているものと、m2TVが理解できるものとで差がありそうで(「TBS」と「TBSテレビ」の違いなど)、実際に試してみる必要がありますが……iEPGに書かれているテレビ局名で録画予約が行えない場合には、テレビ局名の置換テーブルでも用意しておく必要がありそうです(その場合は、とりあえず東京エリアを対象にして試作)。

ただ、実際にm2TVにイベントを送ってみたら……以前は動いていたAppleScript(単に固定パラメータで録画予約するだけ)が動かなくなっていました(ーー;;;; 10.6.3のときには動いていたのですが、10.6.4にアップデートした環境で動いていません。

ここまで作ってみたので、出先でiEPGファイルをダウンロードして、メールに録画情報の文面を入れて送信し……自宅でスタンバイしているMacで録画予約を実行し、本当に録画予約できたかどうか設定ファイルを調べて、メールで返信を行う……といったフローを確立できるかと思っていましたが、この調子ではm2TVではとても無理そうで、大変残念です。

スクリプト名:iEPGのファイルから各種情報を取り出してみるテスト v4
set anAlias to choose file
set aData to read anAlias
set aData to aData as Unicode text

–iEPGのデータから取り出すラベル値のリスト
set pList to {“Content-type:”, “version:”, “station:”, “year:”, “month:”, “date:”, “start:”, “end:”, “program-title:”, “subgenre:”, “genre:”}
set dList to {}

repeat with i in pList
  set j to contents of i
  
  
set aRes to trimStrFromTo2(aData, j, (ASCII character 13) & (ASCII character 10)) of me
  
if aRes is not equal to “” then
    set aRes to repChar(aRes, return, “”) of me
  end if
  
  
set the end of dList to {j, aRes}
end repeat

set bRec to makeRecordFromList(dList) of me

–m2TVで録画予約できるように、iEPGから取り出した情報を適宜組み立てる
set aTitle to | program-title | of bRec

set sTime to | start | of bRec
set sTime to repChar(sTime, “:”, “”) of me

set eTime to | end | of bRec
set eTime to repChar(eTime, “:”, “”) of me

set aDate to | month | of bRec & | date | of bRec

set aStation to | station | of bRec

set m2tvRecStr to “tv “ & aStation & ” “ & sTime & ” “ & eTime & ” “ & aDate & return & aTitle & return

–>
(*
“tv テレビ朝日 2100 2251 0703
土曜ワイド劇場「東京駅お忘れ物預り所4」[デ][字]

*)

on trimStrFromTo2(aStr, fromStr, toStr)
  if fromStr is not equal to “” then
    set sPos to (offset of fromStr in aStr)
  else
    set sPos to 0
  end if
  
  
if sPos = 0 then
    return “”
  else
    set sPos to sPos + 1
  end if
  
  
if toStr is not equal to “” then
    set aLen to length of fromStr
    
set b to text (sPos + aLen) thru -1 of aStr
    
set ePos to (offset of toStr in b)
  else
    set ePos to length of aStr
  end if
  
set aRes to text 1 thru ePos of b
  
return aRes
end trimStrFromTo2

on makeRecordFromList(aList)
  set quotChar to (ASCII character 34)
  
  
set s_header to “return {”
  
set recList to {}
  
set s to “”
  
  
set itemCount to count aList
  
  
repeat with i from 1 to itemCount
    set j to ((contents of item 1 of item i of aList) as Unicode text)
    
if j contains “:” then
      set j to repChar(j, “:”, “”) of me
    end if
    
    
set aLabel to “| “ & j & ” |”
    
set aValue to ((contents of item 2 of item i of aList) as Unicode text)
    
set s to s & aLabel & “:” & quotChar & aValue & quotChar
    
if i is not itemCount then
      set s to s & “,”
    end if
  end repeat
  
  
set s to s_header & s & “}”
  
set aRes to run script (s as Unicode text)
  
  
return aRes
  
end makeRecordFromList

–文字置換
on repChar(origText, targChar, repChar)
  set origText to origText as string
  
set targChar to targChar as string
  
set repChar to repChar as string
  
  
set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to targChar
  
set tmpList to text items of origText
  
set AppleScript’s text item delimiters to repChar
  
set retText to tmpList as string
  
set AppleScript’s text item delimiters to curDelim
  
return retText
end repChar

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

Leave a Reply