1:28 2009/01/20 追記:今更気づいたけど、これってiEPGリーダーto...ってスクリプトだったのか。iEPGを読み込んで辞書に突っ込む関数作れば汎用性が増すんじゃね?
必要なもの
TVスケジューラ2
Python 2.5.2
UWSC(拡張子.uwsをUWSC本体へ関連付け必須)
各自自分でインストールしてください。サポートは出来ませんので。
実行すると全自動で動いてしまうので、必ずアプリケーションを全て終了させてからテストを行ってください。重要なファイルにテキストが書き込まれたり勝手に終了が押されてしまう可能性があります。
TVスケジューラー2の設定
Pythonは
編集→録画予約の設定→iEPGのコマンドテキストに下記のように入力(改行無し)
Pythonのインストールフォルダ\python スクリプトを置いたフォルダまでの絶対パス\AutoRecordingforSEGCLIP.py "%1"
下記のスクリプト2つをファイルを作って、同一のフォルダに保存してください。
ファイル名:AutoRecordingforSEGCLIP.py
# coding: utf-8
""" Editor: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: """
"""
* iodata SEG CLIP3自動録画スクリプト(Python コマンドライン版 + UWSC / 関東近辺限定)
*
* iodata SEG CLIP3とヴァルヘルソフトのTVスケジューラを連携し、全自動で録画する
*
*
* iodata
* http://www.iodata.jp/
*
* TVスケジューラー2
* http://www.valsoft.jp/delphi/tvs2hp.html
*
*
* Python 2.5.2
*
* @author D
"""
# モジュール読み込み
import os
import lib_script
ls = lib_script
#テレビ局名からテレビ局リストのプルダウンでの位置
tvNumConvDict = {
u"tvk" : 0,
u"tvk" : 0,
u"TVKテレビ" : 0,
u"TOKYO MX" : 1,
u"TOKYO MX" : 1,
u"MXテレビ" : 1,
u"フジテレビ" : 2,
u"TBSテレビ" : 3,
u"テレビ東京" : 4,
u"テレビ朝日" : 5,
u"日本テレビ" : 6,
u"NHK教育" : 7,
u"NHK総合" : 8,
}
#ジャンルとプルダウンの順番テーブル(未実装)
tvGenreConvDict = {
u'ジャンルなし': 0,
u'ニュース/報道': 1,
u'スポーツ': 2,
u'情報/ワイドショー': 3,
u'ドラマ': 4,
u'音楽': 5,
u'バラエティ': 6,
u'映画': 7,
u'アニメ/特撮': 8,
u'ドキュメンタリー/教養': 9,
u'劇場/公演': 10,
u'趣味/教育': 11,
u'福祉': 12,
u'その他': 13,
}
line = ls.readTVPTI()
#取得した配列を展開
for i in line:
if i.find(": ") > -1:
arr = i.split(": ")
if arr[0].find("station") > -1:
tvName = arr[1]
elif arr[0].find("year") > -1:
tvYear = arr[1]
elif arr[0].find("month") > -1:
tvMonth = arr[1]
elif arr[0].find("date") > -1:
tvDate = arr[1]
elif arr[0].find("start") > -1:
tvStart = arr[1]
elif arr[0].find("end") > -1:
tvEnd = arr[1]
elif arr[0].find("program-title") > -1:
tvTitle = arr[1]
#SEG CLIP起動コマンド
bootSEGCLIPCommad = ls.publishBootSEGCLIPCommand()
#番組名を60文字以内に丸める
tvTitle = tvTitle[:127]
#\/*:<>|?"はWindowsでファイル名に使えないので削除
tvTitle = ls.delNgWordByWindowsFileName(tvTitle)
titleCommandStr = ls.publishTitleCommand(tvTitle)
#予約種別コマンド
reserveAssortCommandStr = ls.publishReserveAssortCommand()
#チャンネルコマンド
tvNum = tvNumConvDict.setdefault(tvName, 'false')
channelCommandStr = ls.publishChannelCommand(tvNum)
#ジャンル
genreCommandStr = ls.publishGenreCommand()
# 時間処理
tvStartHour, tvStartMinute = tvStart.split(':')
tvEndHour, tvEndMinute = tvEnd.split(':')
#時間キーコマンドを出力
insertDateStrTuple = (
tvYear,
tvMonth,
tvDate,
)
insertTimeStrTuple = (
tvStartHour,
tvStartMinute,
tvEndHour,
tvEndMinute,
)
dateCommandStr = ls.publishDateCommand(insertDateStrTuple)
timeCommandStr = ls.publishTimeCommand(insertTimeStrTuple)
# 予約ファイル生成
uwscDat = ls.uwscLockHardTrue()\
+ bootSEGCLIPCommad\
+ ls.uwscSleep(1)\
+ titleCommandStr\
+ reserveAssortCommandStr\
+ channelCommandStr\
+ genreCommandStr\
+ dateCommandStr\
+ ls.uwscKeyTab()\
+ timeCommandStr\
+ ls.uwscKeyEnter()\
+ ls.publishAppliCloseCommand()\
+ ls.uwscLockHardFalse()
uwscSavePath = ''
uwscSaveFile = 'reserve.uws'
uwscSaveFileFullPath = uwscSavePath + uwscSaveFile
fp = open(uwscSaveFileFullPath, "w")
fp.write(uwscDat.encode('utf-8'))
fp.close()
# 予約用ファイルをresermailに送る
os.system(uwscSaveFileFullPath)
ファイル名:lib_script.py
変更が必要?:publishBootSEGCLIPCommand関数,publishAppliCloseCommand関数の906,710などの数字。この値はウィンドウの位置とマウスポインタの位置を指定しているので、環境によっては、UWSCで録画をして設定してください。(0,0の値は変更不要)
# coding: utf-8
import sys
import re
def readTVPTI():
#TVPTIファイルを配列に格納
tmpList = []
for tmp in file(sys.argv[1], 'r'):
tmp = unicode(tmp, "shift-jis") # unicodeにエンコード
tmpList.append(tmp.strip()) # 読み込んだ行を配列に追加
return tmpList
def oneWordSlicer(checkWord):
#1文字で均等に区切る
cmpl = re.compile('(.)', re.UNICODE)
sliceList = cmpl.split(checkWord)
#空の要素を削除したリストを生成
result = delNullValueByList(sliceList)
return result
def delNgWordByWindowsFileName(checkWord):
#\/*:<>|?"はWindowsでファイル名に使えないので削除
#削除時に不要なスペース、改行を削除
resultWord = re.sub("\\\|/|\*|:|<|>|\||\?|\"", "", checkWord)
result = resultWord.strip()
return result
def delNullValueByList(checkList):
#空の要素を削除したリストを生成
result = []
for val in checkList:
if val != '':
result.append(val)
return result
def uwscKeyDownLoop(dwnInt):
result = ''
for val in range(dwnInt):
result += "KBD(VK_DOWN,CLICK,40)\n"
return result
def uwscKeyInput(inpStr):
return "KBD(VK_%s,CLICK,40)\n" %inpStr
def uwscKeyTab():
return "KBD(VK_TAB,CLICK,40)\n"
def uwscKeyRight():
return "KBD(VK_RIGHT,CLICK,40)\n"
def uwscSetClipbord(setWord):
return "SENDSTR(0,%s)\n" %setWord
def uwscKeyCTRLDown():
return "KBD(VK_CONTROL,DOWN,40)\n"
def uwscKeyCTRLUp():
return "KBD(VK_CONTROL,UP,40)\n"
def uwscKeyV():
return "KBD(VK_V,CLICK,40)\n"
def uwscKeyEnter():
return "KBD(VK_RETURN,CLICK,40)\n"
def uwscKeyALTDown():
return "KBD(VK_ALT,DOWN,40)\n"
def uwscKeyALTUp():
return "KBD(VK_ALT,UP,40)\n"
def uwscKeySpace():
return "KBD(VK_SPACE,CLICK,40)\n"
def uwscKeyFunction(funcInt):
return "KBD(VK_F%d,CLICK,40)\n" %funcInt
def uwscKeyEscape():
return "KBD(VK_ESC,CLICK,40)\n"
def uwscPast():
#uwscの貼り付けコマンドのラップ
command = uwscKeyCTRLDown()
command += uwscKeyV()
command += uwscKeyCTRLUp()
return command
def uwscAppliClose():
#uwscのアプリを閉じるコマンドのラップ
command = uwscKeyALTDown()
command += uwscKeyFunction(4)
command += uwscKeyALTUp()
return command
def uwscSleep(time):
return "SLEEP(%d)\n" %time
def uwscLockHardTrue():
return "LOCKHARD(TRUE)\n"
def uwscLockHardFalse():
return "LOCKHARD(FALSE)\n"
def publishBootSEGCLIPCommand():
command = 'EXEC("C:\Program Files\I-O DATA\SEG CLIP3\OneSegPc.exe")\n'
command += uwscSleep(2)
command += 'ACW(GETID("SEG CLIP"),906,710)\n'
command += uwscKeyInput(8)
command += uwscSleep(1)
command += 'ACW(GETID("SEG CLIP infoBox"),0,0)\n'
command += 'BTN(LEFT,CLICK,139,47,157)\n'
return command
def publishTitleCommand(pubStr):
#タイトルのコマンド出力
command = uwscSetClipbord('"' + pubStr + '"')
command += uwscPast()
command += uwscKeyTab()
return command
def publishReserveAssortCommand():
return uwscKeyTab()
def publishChannelCommand(dwnInt):
command = uwscKeyDownLoop(dwnInt)
command += uwscKeyTab()
return command
def publishGenreCommand():
return uwscKeyTab()
def publishDateCommand(pubList):
#開始日のコマンド出力
command = ''
for val in pubList:
sliceList = oneWordSlicer(val)
for slVal in sliceList:
command += uwscKeyInput(slVal)
else:
command += uwscKeyRight()
return command
def publishTimeCommand(pubList):
#開始、終了時間のコマンド出力
command = ''
for val in pubList:
sliceList = oneWordSlicer(val)
for slVal in sliceList:
command += uwscKeyInput(slVal)
else:
command += uwscKeyTab()
return command
def publishAppliCloseCommand():
command = uwscSleep(2)
command += uwscKeyEscape()
command += uwscKeyEscape()
command += uwscSleep(2)
command += 'ACW(GETID("SEG CLIP infoBox"),0,0)\n'
command += 'BTN(LEFT,CLICK,906,18,188)\n' #infoBox画面終了ボタン
command += 'ACW(GETID("SEG CLIP"),906,710)\n'
command += 'BTN(LEFT,CLICK,1230,726,300)\n' #SEG CLIPテレビ画面終了ボタン
return command
この記事にトラックバックする(FC2ブログユーザー)



