Posted by & filed under 未分類.

とりあえず。
普段はハイバネートしておいて、録画5分前になると起動する構成。

chinachuは github より取得できる。

参考URL https://github.com/kanreisa/Chinachu/wiki/REST-API

$ cat /usr/local/bin/chinachuNext
#!/usr/bin/env python3
# -*- charset: utf8 -*-

from urllib.request import urlopen
import json
import io
import time


class Reserves:
def __init__(self, url):
response = urlopen(url)

self.o = json.load(io.TextIOWrapper(response, response.getheader('content-type').split('charset=')[1]))

def getNextTime(self):
now = time.time()
for e in [ int(ent['start'] / 1000) for ent in self.o if ent['start'] / 1000 > now ]:
return e

if __name__ == '__main__':
url = 'http://localhost:10772/api/reserves.json'
print(Reserves(url).getNextTime() - 300)

$ cat /etc/pm/sleep.d/81chinachu
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
SHUTDOWN_HELPER=/usr/share/unattended-upgrades/unattended-upgrade-shutdown

case "${1}" in
hibernate|suspend)
if /usr/local/bin/chinachuNext > /sys/class/rtc/rtc0/wakealarm; then
echo Wakeup schedule has been set successfully.
fi
;;
resume|thaw)
echo 0 > /sys/class/rtc/rtc0/wakealarm
# TODO: update epg here
;;
esac

2013/9/5 追記:
pm-utilのスクリプトに誤りがあったので修正 : アラームをセットした場合、再セットする前にリセットする必要がある。 参考
chinachuNextスクリプトも、jsonの冒頭が必ずしも次の番組になっていない場合があるので、実行時よりも後の値を選択するロジックを追加。

Trackbacks/Pingbacks

  1.  chinachuの電源管理向けのスクリプト少々 | haruo31's blog

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です